How to switch branches on a repo using the GitHub UI – 017

Similar to `git checkout <branchname>` you can do something similar on a repo using the GitHub UI.

I’m an extremely visual person. For me to understand a concept, I have to physically see it, even if it is just a drawing representing the concept. For a long time, I thought a branch in Git would only contain the diffs. Seeing a branch represented on GitHub.com helped me appreciate what Git is doing.

Using my random-example repo, I have 2 branches which you can see from the repo bar. In this demo, my master branch does not have a README.md file, but my readme-draft branch contains the README.md file. (Let’s say I used the GitHub.com UI to create the README.md file and committed the file to a readme-draft branch, as seen in previous tips).

You can “switch branches” by clicking the Branch: master button located the top of the repo list of files, and then selecting the name of the desired branch, e.g. readme-draft in the example below.

Branch: master button drop down showing 2 branches

Now when you switch to the readme-draft branch, you’ll see the dropdown button change to indicate the new branch.

viewing the readme-draft branch list of files

A few callouts:

  1. The branch button has changed from master to readme-draft
  2. GitHub tells you where this branch is in respect to the default branch. Note I say default branch and not master branch… more on this in future tips (but know the master is the default when you create a new repository.)
  3. Not only do you see all the same files from before on master, you also see the new README.md. Welcome to the world of Git!

This is when it clicked in my brain that a branch contains a snapshot of whatever it was based off of when created (in this case, readme-draft was created based off of the master branch) and then any modifications made to it (i.e. I added a new README.md file to the readme-draft branch).

Leave a comment