Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using github in Visual Studio - update fork from upstream master

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?

like image 711
cb4 Avatar asked Mar 25 '16 21:03

cb4


People also ask

How do I update git fork with upstream?

Go to your fork, click on Fetch upstream , and then click on Fetch and merge to directly sync your fork with its parent repo. You may also click on the Compare button to compare the changes before merging.


1 Answers

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.

like image 91
cb4 Avatar answered Oct 12 '22 06:10

cb4