We decided to pick up Git for the Vanilla & Garden projects after discussions we had with people from many other companies while we were part of open source discussion forum software this past summer. Git is still a bit of an enigma to me, and I’ve been receiving pull requests from people for a while, and I’ve failed to successfully get their changes into my code – instead opting to just manually apply their changes with my own IDE. That is, of course, a total waste of my time and contrary to the entire purpose of us adopting Git. So, today I finally sat down and dug my way through to figure out how to handle a pull request.

After a few hours of frustration, it finally makes sense. Here’s the long and short of it: Define the user’s remote repo, get a local copy of their work, go into the branch you want to pull their changes into, and cherry pick their commit into your branch.

Here are the actual commands I used to accomplish this for a number of different pull requests today:

Step 1. Do you already have their repo set up as a remote branch on your dev machine? Check with:

git remote -v

If not, add the remote branch and fetch the latest changes with:

git remote add -f <username> git://github.com/<username>/Garden.git

Note: “Garden” is the name of our project on github. Obviously, you would need to substitute that for your project name.

2. Do you already have a local copy of their repo? Check with:

git branch -a

If not, create it and check it out with:

git checkout -b <username>/master

If you do already have a local copy of their repo, fetch the latest changes:

git fetch <username>

3. Get their changes into your personal working branch:

git checkout master
git cherry-pick <hash of user's specific changes that they requested you to pull>

That’s it. I can’t believe it took me so long to figure that out!

Leave a comment