Merging changes after a successful pull request back into your fork using EGit
Yesterday I finally had the incentive to download Git so I could fork a Github project (Mustache.cfc) and contribute some changes I'd made. Being that Eclipse is my main IDE, EGit seemed to be a logical client to install. The install process was painless and I was able to figure out how to clone a local copy, commit and push changes back to Github. Even the Github pull request process was painless. Much to my chagrin, my pull request was accepted almost immediately and merged back into the main branch.
Naturally the next thing I wanted to do was to sync my fork with the original repository. This is where I got stuck. Whether due to my lack of understanding of Git terminology or just a lack of my Google Search skills, I was not able to easily find instructions for how to sync the original repository back to my fork. After much searching, I was finally able to find some help.
However, I figured I'd clean up the instructions a bit and provide a little more detail on the steps for merging the main repository back into your fork.
The first thing you need to do, is set up a new remote repository linked to your fork:
- Open the "Git Repositories" view (Window > Show View > Other > Git > Git Repositories)
- Locate your local copy of the fork
- Expand the "Remotes" branch (you should see a "origin" entry)
- Right-click on "Remotes" and select "Create Remote"
- Enter a name representing the master repository, for this example I'll use "mainrepo"
- Select the "Configure fetch" option
- Click "OK"
- Go to the main repository in your browser
- Copy the Git URI into your clipboard
- Go back to Eclipse
- Click on the "Change" button
- Paste the URI into the "URI:" field
- Click "Finish"
- Click the "Add…" button
- In the "Source" field, type in the name of the branch you want to import from.
NOTE: In most cases if you start typing "m", it should show you an auto-complete entry with the "master" branch—just select that option to sync to the master branch.
- Click "Finish" (or click "Next" if you want more options)
- Click "Save and Fetch"
Now that you have a linked the original repository to your fork, you can merge changes from the original repository to your fork:
- Right-click on your project and go to Team > Merge
- Under "Remote Tracking", find the "mainrepo/master" (or the appropriate repository/branch based on the remote repository you just configured.)
- Click "Merge"
- If your repository is up-to-date, there's nothing else to do.
- Finally, just commit your changes locally and push back to the upstream
These steps worked for me, so hopefully they'll help guide someone else!
Posted by Dan
Apr 5, 2012