How would I add associate a remote GitHub repository to a local repository in the Visual Studio 2019 Team Explorer?

Viewed 578

How would I associate remote repository from the Visual Studio 2019 Team Explorer to a local repository? There does not seem to be any way to specify the GitHub URL of a remote repository in Team Explorer or Visual Studio 2019.

The steps I am using are below.

  1. Create a new solution in Visual Studio 2019.
  2. Do a File | Add to Source Control to add a local repository.
  3. Go to GitHub on the Internet and Sign In.
  4. Create a new repository with a ReadMe and Visual Studio setting.
  5. Copy the URL for the newly create remote repository.
  6. Switch back to Visual Studio 2019.

There is no setting in the Team Explorer to specify the URL for the remote repository. How would I specify the GitHub repository in Team Explorer or Visual Studio 2019? Is there any way to Publish in Visual Studios 2019 for Windows or is this only available for Mac?

3 Answers

If there is no obvious settings in Visual Studio itself, you can switch back to command-line, and go to the root folder of your project/git repository:

git remote add origin https://url/to/new/repo
git branch -u origin master
git stash
git pull --rebase
git stash pop
git push

The first pull --rebase is necessary to replay your local commits on top of the remote GitHub master commit (with its README and setting files)

Then open Visual Studio back up, and check it detects the association between your local repository and your remote GitHub one.

You can configure remotes in Team Explorer, although the setting is a little buried. In the Team Explorer Settings page, click the link for Git Repository Settings, and there should be a section that holds the remotes. You can add or edit remotes there.

Hope this helps.

Related