Tag: repos

How to merge your own pull request on a branch you created on your own repo – 022

Today’s tip completes the workflow started in Tip 019 – How to create a pull request for existing branch in your own repo. The scenario is you have a readme you’ve created on a branch and it’s ready to be merged. Even though you are the only contributor to the repo, you still have to use a Pull Request to merge, if you are using GitHub.com to handle the merge instead of command line.

Remember, a pull request is the start of a conversation, even if you are the only developer on the repo. Reviewing your own Pull Requests is kinda like practicing conversational French by yourself. Nothing wrong with practicing your vocalization, but a Pull Request was designed to get points of view from other people. Consider the following true-story exchange:

Host family: “Est-ce que tu veux dîner?” (Want to go to dinner?)

Me: “Non, J’ai faim,” as I shake my head no saying “I’m hungry”

Host family: O_o

In yesterday’s tip we saw that master (the base branch) has 13 commits (at the time of this blogging),

master branch showing 13 commits

but readme-draft branch (the target branch) has 16 commits.

readme-draft branch contains 16 commits

Using my random-example repo, you’ll watch me merge Updated the readme (PR #1) into the master branch in the steps below.

This branch has no conflicts - Merge pull request

Two things to note

  1. There are no conflicts with the base branch (aka master) because we’re adding a new file that doesn’t currently exist in master
  2. There are options to how we could merge this pull request (the dropdown arrow in Merge pull request), but you’ll read more about these in upcoming tips.

Clicking on Merge pull request presents you with a form to fill out

Merging a pull request form

“What?? Another form?? Didn’t I already fill out a form when I created the Pull Request???”

My thoughts exactly Smile When you created a Pull Request, you filled out a form to start a conversation. This form is documenting the merge. These comments will live in the Git log, whereas the Pull Request title and comments live on GitHub.com.

In the scenario where you are making a code contribution to someone else’s repo (i.e. a repo you don’t have commit access to), you wouldn’t see these options to do the merge. But in the case where you want to merge branches in your own repo, you are documenting that you approve and merge your own code, aka you’re merely having a conversation with yourself! Smile

Use the default comments and click confirm merge and you should see the following message:

Pull request successfully merged and closed

Going back to the repo homepage, you know see that master has gone from 13 commits to 17 commits (13 original commits + 3 commits from readme-draft + 1 commit for the merge = 17 commits)

master now showing 17 commits

I’m covering the easiest scenarios right now to get warmed up, and also, because I’ve never tried playing with the other Merge pull request dropdown options yet. But that’s why I’m doing this series… to force myself to learn!

How to see a list of which commits a branch contains on GitHub – 021

I’m calling out this functionality now because after 2 years of using GitHub, today is the first time I’ve ever noticed this button on this page! And it’s sitting right in front of me!! O_O

At the time of this writing, my readme-draft is 3 commits ahead of master.

This branch is 3 commits ahead of master

But suppose you want to see which commits these are.

First, switch back to the master branch (just to get the commit ID of the last commit there that readme-draft was based on, since I haven’t updated master since.)

In my example, my master branch only has 13 commits. Click on this Commits link directly above the language bar.

Commits link above the language bar

Now you’re looking at all the commits for this master branch. Note the last commit on master is “Delete README.md”

List of all commits for master branch

Now at the top of the page, you’ll notice the button I’ve failed to see for the past 2 years.

Branch switcher dropdown button at top of commits list page

Click on the Branch: master dropdown button to switch to the readme-draft branch.

Now you see the list of commits in the readme-draft branch.

list of commits for readme-draft branch

Note that the last commit shown in the image is Delete README.md, which is the last commit on the master branch. Listed above are 3 additional commits in the readme-draft branch, as the first image of this blog post said there were 3 commits ahead of master.

You could (and should) compare commit IDs, listed on the far right of each commit, since the commit message could be the same for different commits. But for this trivial example, I’m only showing the titles of the commits.

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

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).

How to show user documents and other content (readme) at the bottom of your GitHub repo homepage – 016

One of the biggest concepts I had to learn when using GitHub.com the first time is that the much of the repository metadata comes from content within the repo files themselves. To illustrate, back in the day on CodePlex, your license and homepage content were stored as part of the CodePlex project, instead of being generated based on the contents of your repository. Once I made this mental switch, GitHub got a lot easier to use. And FWIW, as I learned in UX grad school, it’s much, much easier to learn a new skill than it is to unlearn an old skill to learn new similar skill.

And what I mean by the title of this post is the content that appears at the bottom of the list of files in your repo. E.g. the electron/electron-api-demos shows a few lines of text and then an image, and then the rest of the readme file.

And yes this is a possible duplicate of #003, but if you don’t know this content is coming from a README.md file, you won’t know you need to add a README file. I felt it important to include these points of view.

readme file for electron/electron-api-demos shown at bottom of GitHub repo

Let’s say that you did not check the Initialize this repository with a README checkbox when you first created your repository.

Initialize this repository with a README

You’ll won’t see the default generated README.md content (which is just the name of your repo and the description, if you provided one).

These days, you’ll see a nice information box encouraging you to create a README.

Help people interested in this repository understand your project by adding a README box

If you click this button, you’ll be taken to the familiar “Create a new file” UI on GitHub, where it creates a new README.md file. If you use all the provided defaults, you’ll get the same generated README file as if you had checked the Initialize this repository with a README button on the new repository page.

auto-generated README.md text showing on GitHub repo homepage

How to view all GitHub keyboard shortcuts – 013

To view all the keyboard shortcuts on GitHub, simply press the question mark key on any GitHub.com page and you’ll see the following image:

Keyboard Shortcuts help window for GitHub.com

Pressing question mark key on any page will show you the shortcuts available, whether they are global (for any page) or for a particular page (e.g. Issues).

And as you’ve figured out by now, the Show All link will show all shortcuts, regardless whether they will work for the page you are currently on, hence why there’s so much whitespace in the image above.

I wanted to share this tip now, so you don’t have to wait for me to discover your favorite shortcut. I’ll go over these more over the upcoming months Smile