Branches are an important feature in many version control systems, but in Git, they’re especially important because they’re so easy to create. In this chapter, you’ll learn how to make branches in your repository. This is sometimes known as diverging your code base. If you want to add a new feature or fix a bug in your repository’s code, you’ll want to create a branch so you can do that work on a copy of your code.
This chapter also covers how to switch between branches, and how to delete branches by using the git branch command. You’ll learn how to jump back and forth among branches by using git checkout. In the next chapter, you’ll bring together (converge) your branched code base.
Branching does introduce questions of how best to use branches. You’ll tackle these policy questions in chapter 17. This chapter is about the mechanics of creating and using branches. Finally, don’t worry if you lose track of the steps as you go through the TRY IT NOW sections; the lab at the end of the chapter introduces a small script that will rebuild your repository to the correct state.
In the preceding chapter, you learned that when you create a repository, Git automatically creates a default branch called master. In this chapter, all the figures show branches like a tree, growing from bottom to top. Like a real tree, Git’s branches grow higher and higher as you make commits.