How to make a commit to a non-default branch using GitHub – 018

Suppose you have multiple branches, and you want to make a commit to a branch that isn’t the default branch (which is almost always master, unless a repo maintainer changed it).

In my random-example repo, I added a README.md file to a readme-draft branch. Suppose you have a similar README.md file in a non-master (or non-default) branch in your repo and you want to update it via the GitHub UI.

First you want to switch to the readme-draft branch by clicking the Branch: master dropdown button.

Branch: master dropdown button switching to readme-draft branch

Second, you’ll want to edit the README.md file. See previous tips for end-to-end walkthrough. In my example, I added a link to the MSDN documentation where I got the sample code.

Next, to save your edits to the README.md file, you can either commit to the readme-draft branch or create a new branch based on the readme-draft branch.

Commit changes either on readme-draft or new branch off of readme-draft

Now if this seems a bit different, it should! Before we were committing to the master branch. This time we’re on a different branch than master, and we could create a new branch (`readme-draft-draft` or `whatever-1`) based off of this current branch (readme-draft).

Again, this is one of those things about Git you have to get comfortable with. Creating a branch is a lightweight process because of how Git works (more on that later, probably late Feb or early March).

For this example, let’s keep it simple. You can commit directly to the current branch, i.e. readme-draft, by clicking the Commit changes button.

Now if you click Code (or go to the repo homepage), you’ll see the following changes:

repo file listing for branch readme-draft 2 commits ahead of master

A few things to notice in the previous screenshot:

  1. You are still viewing the readme-draft branch.
  2. This branch is two commits ahead (1. the creation of the readme.md file – done prior to this tip, and 2. adding the hyperlink to the readme in this commit)
  3. The text `System.Random() from MSDN Documentation` is now blue, indicating the committed hyperlink change

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s