Local Branches

Time to branch out!

Fight the urge not to branch.

Git was designed for frequent branching and merging.

]$ git checkout -b feature-x

To view all of the branches, and see which one you are actively working:

]$ git branch

To switch between existing branches

]$ git checkout [branch-name]

Make changes and commit (like usual)

Done with your feature? Time to merge back into 'master'

First, let's view our diff's (assuming we are still on the feature-x branch)

]$ git diff master

Diffs look ok? Let's merge them in.

]$ git checkout master
]$ git merge feature-x

Now, let's look at our log:

]$ git log

Notice how the commits made to the 'feature-x' branch are now part of the commit history for the master branch

The basic log by itself is not that helpful when looking at branches, so let's add the --graph argument:

]$ git log --graph

Or, for more compressed view:

]$ git log --graph --pretty=oneline --abbrev-commit

The challenge with the default merge is you graphically lose track of what commits were part of the branch.

To retain this helpful information, use the following work-flow:

]$ git checkout -b feature-y
... make changes ...
]$ git add .
]$ git commit -m "[message]"
... switch back to master ...
]$ git checkout master

Now the big difference:

]$ git merge --no-ff feature-y

By adding '--no-ff', the git log will graphically keep the history of the branch in tact.

Give it a shot via:

]$ git log --graph

Last updated