Skip to content

Instantly share code, notes, and snippets.

@scottgonzalez
Last active January 3, 2016 09:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save scottgonzalez/8444896 to your computer and use it in GitHub Desktop.
Save scottgonzalez/8444896 to your computer and use it in GitHub Desktop.
Landing PRs

Update master

First, make sure master is up to date.

git checkout master
git pull upstream master

Rebase your branch

Then rebase your branch, squashing commits and adding a reference to the PR.

git checkout {branch-name}
git rebase -i master

You want to reword (r) the first commit so you can add the PR reference. If there are multiple commits that need to be squashed, you'll want to mark them as fixups (f).

The commit message should contain Closes gh-XXX where XXX is the PR #. This creates a cross-reference to any discussion that took place. If there are multiple commits that will remain after the rebase, only the last should contain Closes gh-XXX, the rest should contain Ref gh-XXX.

Merge into master

Now, merge the rebased branch to master.

git checkout master
git merge {branch-name}

This should always result in a fast forward. If it doesn't, something went seriously wrong with the rebase.

Push to GitHub

Now, push to GitHub.

git push upstream master

If that fails, someone pushed while you were rebasing and you should follow the instructions below the line.

Cleanup

Now that your changes have made it upstream, remove your local and remote branches.

git branch -D {branch-name}
git push origin :{branch-name}

Reset master to match upstream

Get your master branch back in sync with the official repo.

git reset --hard upstream/master
git pull upstream master

Rebase your branch

Rebase your branch again. The squashing and commit message editing are already done, so we can just do a standard rebase.

git rebase master

Continue as above, starting from Merge into master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment