Tag: pull requests

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 add changes to a Pull Request after you have already created a Pull Request – 020

If I could go back in time, this is one of the first tips I’d tell myself about using GitHub. Don’t think of a Pull Request as the final submission. Think of a Pull Request as the beginning of a conversation about the code you want to merge. It’s difficult to appreciate how a Pull Request is the start of a conversation if you are the only developer on a project, so you’ll see more tips on using PRs with other users later in the year.

At first, creating a Pull Request feels like you’re submitting a homework assignment. You might think that once you turn it in, that’s it. But that’s actually not the case with a Pull Request!

You can still go back and make edits to your Pull Request by making commits to its branch.

From yesterday’s tip, you followed along how to create a README.md file in a new readme-draft branch, and create a Pull Request to merge it into master. But let’s say you want to add more content to your README.md.

First, you’ll want to switch to the readme-draft branch using the Branch:master dropdown button.

switching from master to readme-draft

In the readme-draft branch, you can click on README.md file and then the Edit this file button on the far right.

In my random-example repo, I’ll add the following sentences to the README.

I’ve switched to real-world sample code because I feel it is easier to grasp Git-related concepts when actual code is being used, rather than using “Hello from File1” or my joke examples. I learned in UX grad school that the more applicable the new information is made, the easier it will be to learn new concepts. You need to have “a hook to hang your hat on,” as the professor would say. E.g. I didn’t find out that cognition means the study of how the brain works, until I was in the 2nd week of class (which was a class called “Cognition”). I was completely lost; whereas all the psychology majors around me were learning the course material faster than Neo learning Kung Fu. My classmates already had a hook to hang their hats on, whereas I was learning that people study this stuff without going to med school.

Now commit these changes to the readme-draft branch (not a different branch). 

Commit changes form for committing to readme-draft

So what’s happened?

Let’s pretend we never created a Pull Request. If you go to the readme-draft branch, you see your changes, just as you’d expect from previous tips.

readme.md showing updates in readme-draft branch

But we already created that Pull Request, so let’s take a peek at it.

Go to the Pull Requests tab, and click on Updated the readme to view the Pull Request.

Pull request now showing the most recent commit to the branch

The item circled is the commit we just did. Remember, this list above is of commits and not the files that were modified. I can’t recall how many times I’ve had to silently remind myself this.

How to create a Pull Request for an existing branch in your own repo in GitHub – 019

Yep, if you’ve been reading this series, you knew this tip was coming.

For explanation purposes, I’m going to ignore for now the Compare & pull request buttons you’ve probably been seeing if you’ve been following along at home. Why? Because I find it more straightforward to explain how things work when you have to set it up manually the first few times. Otherwise, it’s just magic happening under the scenes.

The scenario is you’ve created a README.md file in a branch called readme-draft on your repo. You created the README.md file in this non-master branch, because you wanted a few days to work (and sleep) on your writing. Now that you are ready to commit the file, you want to merge it into master. Let’s also assume (for now) you are like me, a solo developer on many of your repos.

(aside: I’m pretty sure the only way to do a merge on GitHub is via a Pull Request, even if you are the only developer. Here’s the corresponding SO question/answer to sanity check.)

First, you’ll click on Pull requests tab. (It doesn’t matter which branch you are currently viewing.) Then click on the New pull request button.

New Pull Request button on Pull Request tab

Next you’ll need to specify that you want the readme-draft branch (head) to be merged into the master branch (base).

(If you tried the other way, you’ll immediately get a message that “readme-draft is up to date with all commits from master,” because remember, the readme-draft was based from master only 2 commits ago.)

compare: master dropdown button switching to readme-draft

Alrighty, lots happening on this page, but let’s chill, and only pay attention to 3 things, plus some lagniappe.

Comparing changes page of a Pull Request

On this comparing change page, you’ll see the following items:

  1. Able to merge. These branches can be automatically merged – Awesome. This means no merge conflict, so we’re good. We’ll cover merge conflicts later. It’s only mid-January Smile
  2. Create pull request – This is the action you’ll take next.
  3. 2 commits – something that took a bit of getting used to for me is that this is the number of commits included in this branch, and not the number of files.
  4. Guides – using pull requests –  there’s a little help button sitting off to the far side taking you to the about pull requests guide.

Press the Create pull request button and the Open a pull request form appears.

Open a pull request form page

“What? Another commit form????”  Well, that was my first thought creating my first Pull Request (or PR as I might sometime refer to it as).

My second thought was, “why doesn’t GitHub just use my last commit?” But recall, your last commit is just that… your last commit to a branch. It might say “fix typo” whereas the other 5 commits might talk about all the changes and updates you made to that branch. So you need a new form to represent all your work on that branch.

My third thought was “okay, on closer look, this isn’t the standard commit form after all. So… where does this title and description go?” Glad I asked. This title “Updated the readme” and description “In this pull request…” will be shown as an item on the Pull Request page for the repo (the page when you click on the Pull Request tab.) Think of this as the overall description for your branch.

Without further ado, click Create pull request.

Updated the readme pull request created

And there you go! Your first pull request!

The Pull Request has been created. Note this does not mean your code has been merged. This just means your branch as been marked as wanting to be merged, in case there are other contributors on your repo that want to give you feedback. Your code will be merged once you click the Merge pull request button, but we’ll stop here for today. We’ll cover everything on this page in future tips.

Instead of providing end-to-end walkthroughs, my goal is to provide the smallest, yet practical, bites of information to chew on for 24 hours at a time. This is my personal spin on how to best deep dive into things.

How to create a branch via the GitHub UI without creating a Pull Request – 014

You don’t have to use the command line to create a branch. You can also create a branch directly on GitHub.com. And even though the Create a Pull Request page appears, you can cancel out of it.

Suppose you want to make changes to a readme, but you know you want to make a few iterations on the file before it is final. Or perhaps you want to preview the readme as it will appear to visitors of your repo before it goes “live” on the master (default) branch. Using branches is a great way to store your changes online (where others can still see) that’s separate from the master branch.

First, you’ll click the README.md file in the repo file list.

Clicking readme.md in the repo list

Second, you’ll click the Edit this file button on the far right of the file.

clicking Edit this file on far right side

Next, you’ll make your changes. For my example, I’ll add some content and a link back to MSDN Documentation. (Don’t forget to Preview Changes!)

Lastly, instead of using the defaults to commit directly to the master branch, you can specify to Create a new branch for this commit and then click Propose file change.

Create a new branch for this commit selected

Note in the image above I created a branch called readme-draft, but any branch name will do, including the default name generated (not shown, but it is usually username-patch-1).

The next screen to Open a pull request might feel like it is required, but it is optional. Your branch has already been created.

Open a pull request page

Simply click on Code tab or anywhere else to leave this page. You can always go back and create a pull request later, which we’ll cover.

Pull requests 0 and branches 2