The document discusses the importance of branching and merging in Git for version control. It explains how branches help manage different features or bug fixes without affecting the main codebase, allowing for isolated development. Additionally, it covers the mechanics of switching active branches and the merging process to integrate changes from one branch into another.
The World WithoutBranches
Login Feature New Design #1 Bugfix #213
C1 C3 C7C5C2 C6C4
CHAOS
What happens if your client doesn’t
like “New Design #1”? How do you
get (only) that code out?
If “Login Feature” introduces a bug,
all of your code contains this bug!
What if you need to release “Login
Feature”? It already contains “New
Design #1” - which you maybe
don’t want to release…
3.
Branches to theRescue
C1 C5
Login
Feature
New Design #1
Bugfix #213 C4
C3 C7
C2 C6
each topic gets its own context,
completely separated from
any other context
- If something goes wrong, only this context has the problem!
- Creating and deleting contexts is quick & easy!
4.
Pointers and theHEAD
C1
C2
C3
contact-form HEAD
master
branches are just pointers
on commits (no magic…)
at any time point in time,
only one branch can be
active = checked out = HEAD
in Git, you are always
working on a branch!
5.
Switching the ActiveBranch
the “checkout” command moves the
HEAD pointer to a different branch -
and thereby makes that branch active
$ git checkout master
C1
C2
C3
contact-form
master HEAD
6.
Switching the ActiveBranch
to switch the active branch
simply double-click it
in a desktop app like Tower
all local branches are
listed in the sidebar
7.
Merging Branches
$ gitmerge contact-form
merging integrates all the commits
(the ones you don’t have, yet) from the
specified branch into your current HEAD
C1
C2 contact-form
master HEAD
C3
C4
merge commit
C5
8.
Learn Git withour free online book on
www.git-tower.com/learn