Creating and merging branches with git
If you are maintaining an application you may need to return to an earlier branch to test. For instance, the bug you're fixing may have been around, but unreported, for a long time. You'll want to find when the bug was introduced to track down the code that introduced it. (Refer to git bisect
in the Finding bugs recipe in this chapter.)
When you add new features, you should create a new branch to identify your changes. The project maintainer can then merge the new branch into the master branch after the new code is tested and validated. You can change and create new branches with the git's checkout
subcommand.
Getting ready...
Use git init
or git clone
to create the project on your system.
How to do it...
To change to a previously defined branch:
$ git checkout OldBranchName
How it works...
The checkout subcommand examines the .git
folder on your system and restores the snapshot associated with the desired branch.
Note that you cannot change to an existing branch...