Git: How to Merge a New Pull Request

I originally wrote this as Git: How to Merge a Remote Fork on LiveJournal, but Google refuses to index my LJ, so I couldn’t find it when I needed it. I’m reposting this here for my own future benefit.

James Britt just updated the documentation to TourBus for me, and he pushed the changes to his own fork. Here’s how I pulled it into my own repository without forcibly overwriting my own work until I was ready to merge it. James’ fork is at http://github.com/jamesbritt/tourbus.

Comments are welcome, especially if you know a better way to do it.

In English: Add a remote to my local repository, for James’ remote. Fetch his changes. Diff his changes against master. Assuming approval of his changes, check out master, merge james’ master, and push it.

In Bash:

$ cd tourbus
$ git checkout master
$ git remote add jamesbritt git://github.com/jamesbritt/tourbus
$ git fetch jamesbritt
$ git diff jamesbritt/master
$ git merge jamesbritt-master
$ git push origin master

[Edit: Thanks to Markus Prinz for pointing out the needless tracking branch. I have removed it.]

[Edit: Markus also points out that you can skip the git fetch jamesbritt step if you use -f in the preceding step: git remote add -f jamesbritt git://github.com/jamesbritt/tourbus]

If you need to make changes to get their stuff before merging and you don’t want to do it on master, you should make your own story branch for it:

$ cd tourbus
$ git checkout master
$ git remote add jamesbritt git://github.com/jamesbritt/tourbus
$ git fetch jamesbritt
$ git diff jamesbritt/master # eep, weird changes seen
$ git checkout -b fixmerge # I'm on master, so this will branch from there
$ git merge jamesbritt/master # now we have a master + jamesbritt/master merge. Make changes as needed, then
$ git checkout master
$ git merge fixmerge
$ git push origin master

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s