Branches

I am currently working on tracking my work more thoroughly with Git and GitHub. Naturally, as a consequence of this, I have started to use branches.

Using branches allows you to keep one working version of code (your master branch) then create another branch from the master when you want to develop your code further with a new feature. This new branch is what you continue to work on when building your feature.

This allows your master branch to be unaffected by any undesirable changes you might make. It also gives you greater flexibility when working with other people as you can make pull requests for the branch you’re working from and ask other people what they think of that section of code before you move any further.

When you’re happy with the code on your new branch, you can merge it back to your master branch and then you have an even better master branch to work with. A super branch!

This process continues until you have finished your project.

**Warning** Though it sounds like all fun and games, branching can also be a little tricksy.

If you’ve created a new branch from your master but then switch back to your master branch, make changes and commit them, when you go to merge your new branch to your master, you’ll get a ‘merge conflict’.

This is because Git is confused and doesn’t recognise the new code on the master branch when comparing it to the to copy of the master branch’s previous code used on the new branch. I’m still learning about potential branching pitfalls so I’m sure there are more but this is certainly one of the most frequent problems I have had.