Go to TogaWare.com Home Page. GNU/Linux Desktop Survival Guide
by Graham Williams
Duck Duck Go

Git Branch

20190415 Creating a local branch for every feature development or bug resolution is good practice. Here we create a local-only branch called dev where we might do our local development. We will complete the development, test it and then merge those local developments back into the master branch. Finally we remove the local branch.

To create a new branch we simply ask git to checkout the branch with a new name, dev in this case. The -b option will create the branch and name it.

$ git checkout -b dev

We can list the branches careated using branch

$ git branch
* dev

To optionally register the branch with the remote repository so it is no longer simply a local branch:

$ git push origin dev

We now begin coding and committing to the branch. For example, if we have made changes relating to improving the messages generated by our code we might commit the changes with:

$ git commit -m "Improve messaging." user_interactions.py

If we have registered the branch we can then also push those changes to the remote repository:

$ git push

When we have completed our development activities we will be ready to merge our changes into the master branch.

$ git checkout master 
$ git merge dev

The mergetool command can be used to assist in the task of resolving any conflicts.

$ git mergetool

If the branch is no longer required we can delete the branch from the remote repository.

$ git branch -d dev

Copyright © 1995-2020 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware and the author of open source software including Rattle and wajig.
Also the author of Data Mining with Rattle and Essentials of Data Science.