Merging changes after a successful pull request back into your fork using EGit

Categories: Source Code

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:

  1. Open the "Git Repositories" view (Window > Show View > Other > Git > Git Repositories)
  2. Locate your local copy of the fork
  3. Expand the "Remotes" branch (you should see a "origin" entry)
  4. Right-click on "Remotes" and select "Create Remote"
  5. Enter a name representing the master repository, for this example I'll use "mainrepo"
  6. Select the "Configure fetch" option
  7. Click "OK"
  8. Go to the main repository in your browser
  9. Copy the Git URI into your clipboard
  10. Go back to Eclipse
  11. Click on the "Change" button
  12. Paste the URI into the "URI:" field
  13. Click "Finish"
  14. Click the "Add…" button
  15. 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.
  16. Click "Finish" (or click "Next" if you want more options)
  17. 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:

  1. Right-click on your project and go to Team > Merge
  2. Under "Remote Tracking", find the "mainrepo/master" (or the appropriate repository/branch based on the remote repository you just configured.)
  3. Click "Merge"
  4. If your repository is up-to-date, there's nothing else to do.
  5. 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!

Add Comment

Leave this field empty


If you subscribe, any new posts to this thread will be sent to your email address.