Skip to content

4. Checkout a branch using GitBash

NatashaChetwynd edited this page Jan 2, 2020 · 5 revisions

Checkout a branch using command line

To make changes to the repository e.g. add new code or edit existing code it is good practice to do this on a branch other than the master branch so that any changes do not break a currently working version of the code. Once the repository has been cloned to your local machine, complete the following steps to navigate the branches.

  1. Open GitBash and change your directory to where you have cloned the repository to on your local machine. If you are unsure on how to do this then follow instruction 2 here. You should navigate to the codonPython folder.

  2. Then type the following into GitBash to list all available branches

$ git branch -a

All of the currently available branches will be listed. You can then use the branch names as a reference to navigate and checkout the desired branch. The branch with a * next to it is the branch you are currently on. It is good practice to never make changes directly to the master branch.

Example of branches

  1. Checkout the branch that you want to use by typing the following into GitBash.

git checkout <feature_branch>

Checkout

  1. You can also create a new branch if required using the code below. We suggest that similar pieces of work should be completed on the same branch. Branch names should be simple and indicative of the work being done on that branch - see previous branch names for examples.

git checkout -b <issue/(feature, hotfix etc)/feature_defintion>

⚠️ However, please be aware that when multiple users are working on the same branch, you should regularly update your local branch using the command git pull. This will pull all changes that have been pushed to the remote branch.

  1. Use the following code to confirm you are working on the correct branch.

git branch

The branch you have just checked out should now be highlighted with a *.

current-branch