16

I am using the VS extension for github. While logged in to github, I forked a repository. I then created a VS solution from my fork and made some changes.

Two days later, the original repository I forked from (upstream master) was updated. Now I want to pull those updates into VS. Similar questions have answers with command line steps for updating a fork from its original repository, but how can I do this from the VS GUI?

1 Answer 1

33

Like me, you may be new to GitHub, so let's define some terms. Your VS project is a local repository, called a branch in GitHub lingo (it's name is likely 'master'). The original repository is an upstream master. I forked the upstream master (made a copy of it to my GitHub account). Visual Studio calls a repository on GitHub a remote. The default remote is the origin/master. I created a branch from it in VS by clicking FILE, New, Repository..., then selecting my forked copy listed under GitHub in the Connect pane. Now, here are the steps to get it updated from its original repository.

In a Web Browser

  1. Go to the main page of the repository that you forked, or click on the <>Code tab if you are already there.
  2. Copy the URL into the clipboard (click the copy icon to the right of the url)enter image description here

In VS15

1) Add the upstream master to your project:

  1. Open the solution connected with your GitHub local repository.

  2. From the Team Explorer Home, click on Settings, then Repository Settings.

  3. If it is not already expanded, click on Remotes to expand it, then click on Add.

  4. Enter a name (no spaces allowed). If your project name is 'project', then a good choice is 'project-upstream'. The pic shows my choice, which is not as good. In the Fetch field, paste the url you copied from GitHub and click Save.

    addremote3

  5. Navigate back to the Team Explorer Home, click on Sync, then "Fetch".

  6. Select your newly created remote name "project-upstream".
  7. Click Fetch.

2) To update your branch (local repo) from the original master repo:

  1. Go to the Branches pane (Home, then Branches) and click on Merge.
  2. Click on ‘Merge from branch’ and select the upstream remote repository you just added.
  3. Click the Merge button. You should see the status right below Branches: “Merge completed and committed” with a commit number.

    merge1

  4. Verify your branch was updated: Right-click your local repository name (typically called master) under Active Git Repositories, then select View History… The right pane shows a log of all the commits under the ID column. mergeremote

3) Update your fork on GitHub:

  1. Go back to the Synchronization pane. You should see Outgoing Commits(nn) where nn is the number of commits your fork needs to be in sync with the original, upstream master repo.

  2. Click on Sync (or Push, then the Push button). Now there are no outgoing commits.

4) Verify your fork on GitHub was updated: Back in your web browser window, go to your forked copy of the upstream master. The latest commit number there should match your branch (top line in View History…).

After updating your branch with changes from the upstream master, you might decide that the changes are too significant. You can easily leave the remote branch in your GitHub account unchanged by making a new branch. After step 2.4, under Active Git Repositories, right-click the branch and select New Local Branch From… instead of View History…. Then right-click the new branch and select Publish Branch to push it up to GitHub.

6
  • 1
    Great answer. An extra step I needed to perform was to go to the Sync menu and Fetch from the new remote before it was available to merge from. Source
    – TimS
    Jul 19, 2016 at 12:03
  • 1
    Edited answer to include missing step
    – Daryl
    Aug 17, 2016 at 18:12
  • Awesome answer, thanks for taking the time to detail the steps.
    – Mark G
    Nov 29, 2016 at 5:46
  • @MarkG If it helped you, then consider an upvote on the question and answer. Upvoting is fundamental to making SO work. Thx.
    – cb4
    Nov 29, 2016 at 9:45
  • what about VSCode?
    – mesqueeb
    Sep 4, 2020 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.