Documente Academic
Documente Profesional
Documente Cultură
AGENDA
What is GIT?
Cloning a remote repository
Creating a repository
Git config
Adding remote repository
GIT trees
Committing to local repo and pushing commits to remote repo
Pulling code from remote repo
Switching working directory to a past commit
Undoing changes(erasing local commits)
Merging and Conflict Resolution
GIT DiffTool and MergeTool
Git Panoramic View
Stashing
Reverting remote repo to previous commit
GIT-o-LOGY
Ten Command(ments)
PUSH/PULL WORKFLOW
Common Use-Cases
Git related software
WHAT IS GIT?
It is a Distributed Version Control System.
Developed by Linux Torvalds (Founder of Linux).
Each developer machine has his/her own local repository to which code can
be committed.
local.
CLONING A REPOSITORY
It copies the contents from a remote repository to a local repository.
Navigate to any folder on your file system using GIT CMD.
Run the following command.
All the git commands work on the .git folder. A folder turns into a repository
All the GIT commands can run only in the folder containing .git folder.
CREATING A REPOSITORY
To create a repository on your local system.
All you have to do is run the following command in the folder where you
When you run git init and .git folder is created which indicates that a
git init is all you need to put a folders content in version control. We are
GIT CONFIG
Global Settings
> git config --global user.name Gitty Kumar
> git config --global user.name gitkum@gmail.com
Project settings
> git config user.name Gitty
> git config user.email Gitty@gmail.com
Storing credentials so that we dont have to type often. Note that password is
The .gitconfig file is located in .git folder in each local repository and also in the
set automatically
command
GIT TREES
Working Directory: It holds the actual files which we would be working on. It
it is a single file.
> git add . (Add all the files in the current directory to the staging/index area)
Next we need to execute git commit which adds the staged changes to the repository
> git commit m Implemented a new feature (Commits the changes in staging area
to the repository)
Next we need to push our commits to remote repository by issuing the following
command. Note that origin is an alias for the URL which is stored in .gitconfig and
master is the name of the branch to which we want to push our changes.
> git push origin master
Note: Typically pushing code into repository might not be straight forward and we might
have to follow the push/pull workflow flowchart mentioned in the later slides.
It gets the code from remote repository but does not affect with our working directory. It is like
a preview of changes which have taken place in remote repository.
> git fetch origin master
commits in local and remote repository. We need to run the following command to re-apply
our commits on top of the remote commits.
commit mentioned in the command. Resets the staging area to the repository. It
affects only the staging area and repository.
> git reset 123asfasdf32434
Same as the above command but it changes the files in the working directory. After
this command the working directory, staging and repository are in sync
> git reset --hard12sresfasdfs343
Resetting your working directory to the remote repositorys latest commit. The below
is useful when you have done some wrong changes and want to go back to the
remote repositorys state.
remote repository branch there is said to be a merge conflict when we pull code
from remote repository(a.k.a. Upstream.).
For instance
Remote repo might have the following commits (a<-b<-c<-d) c being the
latest commit
Our local repo might have the following commits (a<-b<-e<-f) with f being the
latest. When
At this point when we issue git pull there is a merge conflict so git will try to
resolve conflicts automatically but sometimes manually intervention is required in
case if the same file was modified in c and e commit.
The below command gets the latest changesets from the remote repository and
merges them with code in the working directory. If merging is successful this
command executes successfully else we have to manually merge.
> git pull origin master
[mergetool "meld"]
cmd = \"C:\\Program Files (x86)\\Meld\\Meld.exe\" $LOCAL $MERGED
$REMOTE
[difftool "meld"]
cmd = \"C:\\Program Files (x86)\\Meld\\Meld.exe\" $REMOTE $LOCAL
STASHING
In fact, most of the times, we might have some uncommitted changes and when we try to
Your local changes to the following files would be overwritten by merge: Please commit or stash them
At this stage, we might not be interested to commit as we might have not completed the
feature. Instead, we could stash which means temporarily saving your work in a separate
place.
Just execute the following command
> git stash
After this you could run
> git pull
Which will execute successfully. Now you must be wondering how to get back those
uncommitted changes. Just issue the below command which will get the uncommitted
changes back to the working directory.
> git stash pop
GIT-O-LOGY
HEAD: Generally, HEAD should point to a branch. It can also point to a commit
Branch: It is a pointer to the latest commit. Every GIT repository has a default
Each of the branches are also called as head but uppercase HEAD refers to
TEN COMMAND(MENTS)
git clone : Used to clone a remote repository
git add: Used to add files to the staging area.
git commit: Commits the changes present in the staging area to the local repository.
git checkout: Used to switch between branches,
git reset: Erase commits.
git push: Pushes code commits from local repository to remote repository.
git pull:
Pulls code commits from remote repository to local repository and then
merges code. So the changes are reflected in the working directory. So
PULL=FETCH+MERGE
git add .
Start
PUSH/PULL
WORKFLOW
No (Nothing to rebase)
Yes
Is rebase
successful??
No(because of
conflicts)
Is Push
successful??
Yes
git merge
origin/master
(Merges the changes)
git stash
No
Is merge
successful?
?
Yes
Did you
execute git
stash before
Yes
No (Because of merge
conflicts)
COMMON USE-CASES
Ensuring that local working directory exactly resembles the remote
Eclipse has a plugin name E-git for issuing git commands within eclipse
http://www.vogella.com/tutorials/EclipseGit/article.html
windows)