First, make sure master is up to date.
git checkout master
git pull upstream masterThen rebase your branch, squashing commits and adding a reference to the PR.
git checkout {branch-name}
git rebase -i masterYou 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.
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.
Now, push to GitHub.
git push upstream masterIf that fails, someone pushed while you were rebasing and you should follow the instructions below the line.
Now that your changes have made it upstream, remove your local and remote branches.
git branch -D {branch-name}
git push origin :{branch-name}Get your master branch back in sync with the official repo.
git reset --hard upstream/master
git pull upstream masterRebase your branch again. The squashing and commit message editing are already done, so we can just do a standard rebase.
git rebase masterContinue as above, starting from Merge into master.