Once a pull request is deemed satisfactory, anyone with push access to the destination repository can perform the merge. There are a variety of ways to accomplish this. Two popular methods are described below.
Merging directly on Github
If the merge will not have any conflicts, you can merge the pull request online without ever typing a single git command.
- Open the pull request's page
- Click the "Merge pull request" button
- Enter a commit message
- Click "Confirm Merge"
Merging locally
If the pull request cannot be merged online, or you wish to test things locally before sending the merge to the repo on Github, you can perform the merge locally instead. This is also handy if you don't have write access to the destination repo.
Pull
This is the most common method of fetching and applying changes. This method will retain the commit history without modification.
- Click the
(i)button on the left of the merge bar
- Follow the instructions displayed for your pull request.
Note: these will be different for every pull request
If you do not have write access to the repo, you can still run the commands locally:
- Open your local repo in the terminal
-
Check out the branch you wish to merge to
$ git checkout master
-
Pull the desired branch from the other user's repo
$ git pull https://github.com/otheruser/repo.git branchname
Resolve any conflicts and commit the merge
Review the changes and ensure they are satisfactory
-
Push the merge to your GitHub repo
$ git push origin master
Patch and apply
The pull approach works great when you're working on a team or repeatedly applying changes from the same small group of people. Another approach that's a bit quicker in one-off cases is to use git-am.
This method does not maintain the commit history. It is best used for local testing or applying to a repo you do not intend to share. If you are pushing to a remote repo, the pull method described above is preferable.
Every pull request has a special URL where you can grab a patch file to feed into the git am command:
- Visit the pull request page you wish to patch from
- Copy the URL
- Open your local repo in the terminal
-
Check out the branch you wish to merge to
$ git checkout master
-
Download and apply the patch
$ curl http://github.com/otheruser/repo/pull/25.patch | git am