Git Basics
Git Basics
v1.0.0 v1.0.0
v1.0.1 v1.0.1
v1.0.2 v1.0.2
v1.0.2
2 types of VCS
Centralized Distributed
Centralized version control
Helps you backup, track and synchronize files.
You can use git without Github, but you cannot use GitHub without Git.
Git GitHub
Commit changes
Pull request
git push
Push changes
Git Branching
C1 C2 C3
Master Branch
C1 C2 C3 C4 Merge
C1 C2
Master Branch
Feature Branch
Master Branch
Feature Branch
Hotfix Branch
C1
C1 C2 C3 C4 Merge Merge
C1 C2
Merging
Common Snapshot to
Ancestor merge into
C1 C2 C3 C4 Merge
C1 C2
Snapshot to
Master Branch merge in
Feature Branch
What is a Git Merge Conflict?
Merge Conflicts
If there are changes in the working When there is a conflict between the local
directory’s stage area for the current project, branch and the branch being merged.
merging won’t start.
Git resolves as much as possible, but there
In this case, conflicts happen due to pending are things that have to be resolved
changes that need to be stabilized. manually in the conflicted files.
Merge Conflicts
Occasionally, this process doesn’t go smoothly.
If you changed the same part of the same file differently in the two branches
you’re merging, Git won’t be able to merge them cleanly. If your fix for feature
branch modified the same part of a file as the hotfix branch, you’ll get a merge
conflict that looks something like this:
Git hasn’t automatically created a new merge commit. It has paused the process
while you resolve the conflict. If you want to see which files are unmerged at any
point after a merge conflict, you can run git status:
Anything that has merge conflicts and hasn’t been resolved is listed as unmerged.
Git adds standard conflict-resolution markers to the files that have conflicts, so you
can open them manually and resolve those conflicts. Your file contains a section
that looks something like this:
The version in HEAD (your master branch, because that was what you had
checked out when you ran your merge command) is the top part of that block
(everything above the =======), while the version in your feature_branch looks
like everything in the bottom part. In order to resolve the conflict, you have to
either choose one side or the other or merge the contents yourself. For instance,
you might resolve this conflict by replacing the entire block with this:
git commit
Git commands to resolve conflicts
● git log --merge: produce the list of commits that are causing the
conflict.
● git diff: Identify the differences between the states repositories or files.
● git checkout: Used to undo the changes made to the file, or for
changing branches.
● git reset --mixed: Used to undo changes to the working directory and
staging area.
● git merge --abort: Helps in exiting the merge process and returning
back to the state before the merging began.
● git reset: Used at the time of merge conflict to reset the conflicted files
to their original state.