Plan-->Idea / Innovation-->Explore-->Experiment-->Implement-->Gain Knowledge. um Aricent
Melden
Bildung
A Beginner's Guide to Git and GitHub, CLI version.
What is Git?
What is Github
Basic commands
Difference between Central and Distributed Version Controlling System
2. Hub4techie.com Anurag Deb Roy
What is Git:
Git is a version control system, a tool to manage your source code history.
I.e. to track all the changes made to the file.
"Git is a free and open source distributed version control system designed to handle
everything from small to very large projects with speed and efficiency"
Centralized vs Distributed Version Control System
Drawbacks : If anything happens in central repository, we don’t have any backup.
Distributed Version Control System
3. Hub4techie.com Anurag Deb Roy
Backup is made in local repository.
Only need to be online when changes are committed to main server.
What is GitHub:
GitHub is a hosting service for Git repositories.
"GitHub is a web-based Git repository hosting service, which offers all of the distributed
revision control and source code management (SCM) functionality of Git as well as adding
its own features."
Github provides access control and several collaboration features such as wikis, task
management, and bug tracking and feature requests for every project.
You do not need GitHub to use Git.
GitHub (and any other local, remote or hosted system) can all be peers in the same
distributed versioned repositories within a single project.
Github allows you to:
● Share your repositories with others.
● Access other user's repositories.
4. Hub4techie.com Anurag Deb Roy
● Store remote copies of your repositories (github servers) as backup of your local
copies.
Architecture
Privileges/Access Levels
Owner
Has full administrative access to the entire organization.
Member
Can see every member and non-secret team in the organization, and can create new
repositories.
Let’s Start workingwith Git commandLine
$ git --version
git version 2.16.2.windows.1
Now we need to set up some global configuration.
Why Important ?
Because if you are working with other developers then everybody needs to know who is
checking in & out or making the changes.
$ git config --global user.name "Anurag Deb"
$ git config --global user.email "anuragdeb8@gmail.com"
To check all the configurations done
$ git config --list
core.symlinks=false
5. Hub4techie.com Anurag Deb Roy
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
rebase.autosquash=true
http.sslcainfo=E:/Git_Install/mingw64/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
user.name=Anurag Deb
user.email=anuragdeb8@gmail.com
NEED Help ?
git help <verb>
Ex : git help config Or
git <verb> --help
Ex : git config --help // git-config.html will open
6. Hub4techie.com Anurag Deb Roy
Getting Started
Two common Scenarios :
1) Existing Project/Repo
2) New Project/Repo
A new repo from scratch
Say you’ve just got some data from a collaborator and are about to start exploring it.
● Create a directory to contain the project.
● Type git init // initialized empty GIT repository in .folder path
● git status // nothing to commit
● dir > test1.txt //Creates text file
Ignore some files if you don’t want to track those files.
$ touch .gitignore
Edit .gitignore
.Project //any folder you don’t to track
*.bat //any file you don’t to track
After adding check git status.
Where are you now?
Working Directory : you are working right now.
Staging Area : We organise what we want to commit to our repository
Repository : Local repository
7. Hub4techie.com Anurag Deb Roy
Lets Start
● Type git add to add the files so that we start tracking the files
● Type git add -A // to add all files
● Type git commit
But it’s good to add messages while doing commit.
Use git commit -m “message”
Mukta@Mukta-PC MINGW64 /E/Study/GitTuts/LocalRepo (master)
$ git commit -m "Initial commit"
[master (root-commit) 964b9f5] Initial commit
3 files changed, 212 insertions(+)
create mode 100644 .gitignore
create mode 100644 ShellScript.sh
create mode 100644 ShellScriptFile2.sh
$ git status
On branch master
nothing to commit, working tree clean
$ git log
commit 964b9f51604c8bdf854a47d7f6ba497e64015b58 (HEAD -> master)
Author: Anurag Deb <anuragdeb8@gmail.com>
Date: Sat Mar 24 23:42:18 2018 +0530
Initial commit
Second Scenario : Existing Repository
$ git clone <url> <where to clone>
$ git clone ../remote_repo.git .
$ git clone https://github.com/anuragdeb3/Loadbuster .
Viewing Information aboutthe remote repository
8. Hub4techie.com Anurag Deb Roy
$ git remote -v
$ git branch -a
Pushing Changes (After Some changes to the code)
git diff
git status
git add -A
git commit -m “added some print lines”
While we were working on our code there might have been changes in the files done by some other
developers, That’s why we need to pull first then push the code.
$ git pull origin master
Will pull any changes from the last time we did the pull operation.
Origin : is the remote repository.
Master : It is the branch where we want to push to.
For now we have worked with local and remote repositories.
Let us Check out the workflow
Common Workflow
For now we were directly working on the master branch.
Branching is the way to work on different versions of a repository at one time.
By default your repository has one branch named master which is considered to be the definitive
branch. We use branches to experiment and make edits before committing them to master.
When you create a branch off the master branch, you’re making a copy, or snapshot, of master as it
was at that point in time. If someone else made changes to the master branch while you were
working on your branch, you could pull in those updates.
Create A Branch For Desired Feature
$ git branch scriptEdits
$ git branch // lists all local branches
* master // * means the current branch we are working on
9. Hub4techie.com Anurag Deb Roy
scriptEdits // if you want to work on another branch you need to checkout to that branch
$ git checkout scriptEdits
Switched to branch 'scriptEdits'
$ git branch
Do some changes to script and changes will be done only to branch not master
$ git status
On branch scriptEdits
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Buster.sh
no changes added to commit (use "git add" and/or "git commit -a")
$ git add -A
$ git status
On branch scriptEdits
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: Buster.sh
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Buster.sh
$ git commit -m "made changes to exit function"
[scriptEdits 757f2d9] made changes to exit function
1 file changed, 2 insertions(+)
After CommitPush Branch To Remote
10. Hub4techie.com Anurag Deb Roy
$ git push -u origin scriptEdits
-u is for set upstream i.e. associate our local branch with the remote branch
$ git branch -a
master
* scriptEdits
remotes/origin/HEAD -> origin/master //pointer to the master
remotes/origin/master
remotes/origin/scriptEdits
After all unit tests we can Merge A Branch
$ git branch -a
master
* scriptEdits
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/scriptEdits
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
$ git branch
* master
scriptEdits
$ git pull origin master
From https://github.com/anuragdeb3/Loadbuster
* branch master -> FETCH_HEAD
Already up to date.
11. Hub4techie.com Anurag Deb Roy
$ git branch --merged
* master // showing only master as other branches have not been merged yet
$ git merge scriptEdits
Updating 757f2d9..efe5a10
Fast-forward
Buster.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
$ git push origin master
Username for 'https://github.com': anuragdeb3
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/anuragdeb3/Loadbuster
6d7f7e5..efe5a10 master -> master
Delete a Branch
$ git branch --merged
$ git branch -d scriptEdits
$ git branch -a
$ git push origin --delete scriptEdits
Download :https://git-scm.com/download/win
Chrome Previous Releases : https://www.slimjet.com/chrome/google-chrome-old-version.php