This is a continuation of a tutorial blog series to learn the basics of Git, using GitHub and the GitHub client.
To start from the beginning, go here.
Now we start to touch on stuff that is a bit more complicated. There is a lot more you can do with branches, this tutorial will serve as an introduction to the concept.
What is branching?
When you make commits on git, you end up with a series of snapshots of the code in various states. What if you wanted keep the code in different states, without having to copy/paste into two different repositories?
For instance, you might have your 1.0 release version, and another 1.1 version for your in-progress new feature update.
What if while you are developing your 1.1 code, somebody finds a major bug that you need to fix from your 1.0 version right away? The new feature you are working on isn’t finished yet, but you don’t need to discard and revert all your hard work to get access to the 1.0 code. Instead, set up a new branch for your release and in-progress code.
What if you have a master version of your code, and you just want to mess around and change things just for testing? You want to be able to commit your work and save what you’ve been doing, but don’t want to mess up your master. You should not afraid to commit test changes because you would then have to revert them back later. Just make a new test branch instead that will not effect your master branch.
Branching allows you to organize your commits and keep track of multiple versions of your code.
This may sound weird at first, but it gets simpler once you see it in action.
Create a branch
By default, all git projects have a “master” branch. There is a drop down box that says “master” on top of your commit log. Click it to expand the drop down menu to view all your current branches.
To make a new branch, go back to your main project screen. The text box should say “Filter or create new”. Type the name of the new branch you want.
Switch between branches
To switch between, click on the drop down menu again.
Now switch back to “master” branch. You’ll see that your new commit disappears. If you check your folder, the files are automatically changed. When you’re ready to work on your new feature again, select the branch again and you can continue working.
To delete a branch, you’ll need to go to your branch manager again. To get there, click the branches drop down menu again and hit the manage button on the top right.
End of Part 3