Git+&+Github+Course +merging
Git+&+Github+Course +merging
Branches
Merging
Branching makes it super easy to work within self-
contained contexts, but often we want to incorporate
changes from one branch into another!
Master
987fac... 236ff...
92faa... 2456...
Bugfix HEAD
❯ git switch master
987fac... 236ff...
92faa... 2456...
Bugfix
❯ git merge bugfix
987fac... 236ff...
Master HEAD
92faa... 2456...
Bugfix
This is what it really looks like
Remember, branches are just defined by a branch pointer
Master HEAD
Bugfix
This is what it really looks like
Master & Bugfix now point to the same commit, until they diverge again
Master HEAD
Bugfix
❯ git merge bugfix
This Is Called A Fast-Forward
Master simply caught up on the commits from Bugfix
Master HEAD
Bugfix
Not All Merges Are Fast Forwards!
We've branched off of master, just like before...
Master
987fac... 236ff...
92faa...
92faa... 2456...
2456...
Bugfix HEAD
What if we add a commit on master?
This happens all the time! Imagine one of your teammates merged in a new
feature or change to master while you were working on a branch
Master
92faa...
92faa... 2456...
2456...
Bugfix HEAD
What happens when I try to merge?
Rather than performing a simple fast forward, git performs a "merge commit"
We end up with a new commit on the master branch.
Git will prompt you for a message.
Master HEAD
92faa...
92faa... 2456...
2456...
Bugfix
What happens when I try to merge?
Rather than performing a simple fast forward, git performs a "merge commit"
We end up with a new commit on the master branch.
Git will prompt you for a message.
Master HEAD
NEW
987fac... 236ff... f4faa...
COMMIT
92faa...
92faa... 2456...
2456...
Bugfix
Heads Up!
Depending on the specific changes your are trying to
merge, Git may not be able to automatically merge.
This results in merge conflicts, which you need to
manually resolve.
❯ CONFLICT (content): Merge conflict in blah.txt
Automatic merge failed; fix conflicts and then commit the result.
<<<<<<< HEAD WHAT THE...
I have 2 cats
When you encounter a merge conflict, Git warns you
I also have chickens in the console that it could not automatically merge.
=======
It also changes the contents of your files to indicate
I used to have a dog :( the conflicts that it wants you to resolve.
>>>>>>> bug-fix
<<<<<<< HEAD
I have 2 cats
Conflict Markers
I also have chickens The content from your current HEAD (the branch you
======= are trying to merge content into) is displayed
between the <<<<<<< HEAD and =======
I used to have a dog :(
>>>>>>> bug-fix
<<<<<<< HEAD
I have 2 cats
Conflict Markers
I also have chickens The content from the branch you are trying to merge
======= from is displayed between the ======= and
>>>>>>> symbols.
I used to have a dog :(
>>>>>>> bug-fix
Resolving Conflicts
Whenever you encounter merge conflicts, follow these
steps to resolve them:
master branch
987fac... 236ff... 92faa... 2456... HEAD
12323 ffa1233
bugfix branch
Deleting A Branch
master branch
987fac... 236ff... 92faa... 2456... HEAD