How to Checkout a branch in a Github repository

What is Checking Out a Branch?

Checkout is the command used to switch between the different branches of a GitHub repository. When a branch is checked out, all files in the working directory are updated to match the versions stored in that branch. Branches make it easy to work with your code base and keep your main projects intact while you test out improvements or modifications.

How do I Checkout a branch?

The Checkout command can be used from the command line in any GitHub repository. Open up your terminal and navigate to your repository on your server or local machine.

  1. The first thing you will need to do is make sure that you have branches in your repository that you can checkout. This is accomplished by entering the command ‘git branch’ in the command line.
  2. After entering the command you will be presented with a list of all available branches in your repository. These are the branches that you can switch to using the checkout command.  Every GitHub repository starts with a master branch and additional branches must be created before you can switch to them.
  3. After confirming that you have available branches to move to, its time to checkout the branch you want to work on. Since we want to make changes without disturbing the master branch, let’s checkout the dev branch. To switch to our dev branch we need to enter the command ‘git checkout’ followed by the name of the branch we want to checkout, in this case ‘dev’.
  4. Now you will see that the working branch of the repository has changed from master to dev. We are now free to make any code adjustments to our repository without disrupting the master branch.

Congratulations! You now know how to checkout a branch in a GitHub project and make changes that are independent of your master branch!


Get more for free by signing up with BoldGrid Central Create Account

Leave a Reply