Local Version Control System
Local Version Control System
System that records changes to a file or set of files over time so that you can recall
specific versions later.
When there was no version control system, Many peoples version-control method
of choice is to copy files into another directory
Installation :-
sudo apt-get install git-core
Version Check :-
git --version
Customize Git Environment :-
Git config path : /etc/gitconfig file: Contains values for every user on
the system and all their repositories.
Setting identity
git config --global user.name Demo"
git config --global user.email [email protected]
Unstaging a file :-
git reset HEAD <file name>
Git Remotes :-
git remote : show short names of remotes
git remote add : add a remote repo
git remote show [remote-name] : inspecting a remote
git push [remote-name] [branch-name] : pushing the changes in a branch
to a remote
The Three States
Review Changes
View commit details :-
git show <commit ID> : Shows the commit details.
git diff : Shows '+' sign before lines, which are newly added
and '' for deleted lines.
Branch Management
git branch : Lists existing branches, including remote branches
if -a is provided. Creates a new branch if a branch name is
provided.
git branch v : Shows last commit on each branch.
git branch merged : To see which branches are already
merged into the branch youre on.
git branch --no-merged : To see all the branches that contain
work you havent yet merged in.
Branches in a Nutshell
Adding changes in a new branch : The New Branch has moved forward with your work
Three way merge :-
Before Merge
After Merge
Merge Conflicts :-
Occasionally, merge process doesnt go smoothly. If you changed the same part of the
same file differently in the two branches youre merging together, Git wont be able to
merge them cleanly and youll get a merge conflict.
<<<<<<< HEAD:index.html
<div id="footer">contact : [email protected]</div>
=======
<div id="footer"> please contact us at [email protected]
</div> >>>>>>>
iss53:index.html
Remote Branches :-
Remote-tracking branches are references to the state of remote
branches. Theyre local references that you cant move; theyre moved
automatically for you whenever you do any network communication.
Rebasing
It works by going to the common ancestor of the two branches (the one
youre on and the one youre rebasing onto), getting the diff introduced by
each commit of the branch youre on, saving those diffs to temporary files,
resetting the current branch to the same commit as the branch you are
rebasing onto, and finally applying each change in turn. The primary
reason for rebasing is to maintain a linear project history.
Merging
Rebasing
Stash & Clean
Stash operation takes your modified tracked files, stages changes, and saves them on a stack of
unfinished changes that you can reapply at any time.
git stash
Now you can safely switch the branch and work elsewhere.
We can view a list of stashed changes by :-
To remove the changes from the stack and place them in the
current working directory :-
git apply