Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pull in changes from a Github fork

Someone forked a Github project of mine and made some changes. How can I merge the changes back in to my upstream version?

Also, is it possible to pull in just a specific commit?

What I'm looking is if there is a way to pull a specific commit instead of the entire branch.

like image 971
gregghz Avatar asked Jan 03 '11 02:01

gregghz


People also ask

How do you pull changes from a forked repo?

To pull down (i.e. copy) the changes merged into your fork, you can use the Terminal and the git pull command. To begin: On your local computer, navigate to your forked repo directory. Once you have changed directories to the forked repo directory, run the command git pull .


2 Answers

Pulling in a single commit would be a cherry-pick and would rewrite the commit ID (and mark you as the committer while retaining the author). The process is pretty straightforward, though:

git fetch git://github.com/user/project.git git cherry-pick <SHA-COMMIT-ID> 

You get the SHA from the repository log, for example:

git log --oneline  b019cc0 Check whether we have <linux/compiler.h>. 0920898 Include <linux/compiler.h> before including <linux/usbdevice_fs.h>. cbf0ba1 Add DLT_DBUS, for raw D-Bus messages. 77ed5cd Libnl 2.x returns its own error codes, not errnos; handle that. 

With git cherry-pick 0920898 you bring the respective commit to your current branch.

like image 67
Dustin Avatar answered Sep 28 '22 09:09

Dustin


There is an awesome tool which is called hub, which provides useful tools to clean up pull requests and generally "helps you win at git".

One useful command in this context is:

git am -3 <url>

This allows you to grab the changes from a url and apply its commits/changes to your current local git without even fetching the remote repository (which comes in handy with large repositories).

If you use this command with the git webpage of the commit you want to grab, you end up with this commit in your git. Even more useful: the commit author is kept and not replaced by you (as it would if you use git rebase). If you push this to your repo, the changes will be committed by you, but authored by the original author.

A very good ressource on this topic is this guide by Nathaniel Talbott. It shows a great workflow to work with pull requests instead of relying on the "malicious" merge pull request button on github.

like image 27
Mr. Anderson Avatar answered Sep 28 '22 08:09

Mr. Anderson