Git TIP - Why you should not keep a local master branch ?

#git
Post available in: Français

When working with git, I have often made the mistake of maintaining a master branch locally updated using these commands.

git checkout master

git pull origin master

I’ve done this so many times. This allowed me to start a development by being up to date with recent changes.

In fact, it is not necessary to maintain local copies of the branches on which we are not working directly. We already have access to an intact local version of the remote branches.

All this time I could have just done:

git checkout origin/master

And when you want to work on new stuff, just use

git checkout -b my-feature origin/master

Keep in mind that this is valid for master as well as all other branches on which you do not work directly/on which you will commit.

You could also follow my colleague advises.

Let me know if you have any other tricks with Git!


Written by Antoine Caron who lives and works in Lyon (France) building useful things at Bedrock. You should follow him on Twitter. Take a look at my friends websites. You could also take a look at the conferences I gave. If you want to see my professional background, my resume is available here.

If you like some content of this blog, or it has helped you, please consider donating to the Abbé Pierre Foundation which I personally support.
"We are only ever happy in the happiness we give. To give is to receive."