GNU/Linux Desktop Survival Guide
by Graham Williams
20190415 Creating a branch to work on a task or issue 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 main branch. Finally we remove the local branch.
To create a new branch we simply ask git to
checkout the branch with a new name,
validator in this case. The
-b option will
create the branch and name it as such.
$ git checkout -b validator
We can list the branches careated using branch
$ git branch * validator main
To optionally register the branch with the remote repository so it is no longer simply a local branch:
$ git push origin validator
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 main branch.
$ git checkout main $ 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