wonderful world
wonderful world

Reputation: 11599

How do I publish a local github repo to Visual Studio Services?

I cloned a GitHub project called nopCommerce locally. I also branched the repo with the command

git checkout -b mybranch

I want to publish this branch mybranch to Visual Studio Services. How can I do that?

This is how my Team Services look like in the Visual Studio 2015.

enter image description here

Upvotes: 1

Views: 4611

Answers (2)

Marina Liu
Marina Liu

Reputation: 38106

You can publish a local github repo to VSTS by below steps:

  1. Download github extension for vs.
  2. Restart vs and log in github in vs.
  3. Clone github repo to a local path.
  4. Replace origin with VSTS URL by Team explorer -> setting -> repository setings -> remote -> edit the origin URL as the git repo in VSTS, such as https://username.visualstudio.com/_git/projectname.
  5. Create a new branch mybranch in vs, branches -> new local branch from -> create branch.
  6. Right mybranch -> publish branch.
  7. Now you can make some changes, commit&push, so the repo will be published to VSTS.

Upvotes: 4

Luca Cappa
Luca Cappa

Reputation: 1999

If you already have a local Git repository on your disk, you do not really need nor the GitHub extension, nor creating a new branch.

You only need to :

  1. get the URL of an empty Git repository on VSTS;
  2. add a new remote with this URL;
  3. push content to the new Git repository using the new remote;

1) get the URL of an empty Git repository

First retrieve the URL of an empty existing repository, or create a new empty repository using the VSTS web interface:

  • From Code Hub, select '+ Repository' to create a new empty Git repository;
  • Retrieve the HTTPS URL to that repository on the Files tab of the repository: it should be of the form

    https://YOURACCOUNT.visualstudio.com/DefaultCollection/TEAMPROJECTNAME/_git/REPOSITORYNAME

Onward this URL will be named with the placeholder 'URL_TO_REPO'.

2) Add a remote to local repository

You could add a new remote (called here 'vsts_origin') by means of Visual Studio, the command line, or a simple text editor:

  • Visual Studio:

    • open the local repository inside the Team Explorer (it must be shown as bold in the Local Git Repository section);
    • Add a new remote by selecting Repository Settings, then selecting Add in the Remote section. Use 'vsts_origin' as the name, and URL_TO_REPO as the Fetch field.
  • command line:

    • run this command to add a new remote called 'vsts_origin' to the local Git repository:

      >git remote add vsts_origin URL_TO_REPO

  • text editor:

    • open the .git/config file with your preferred text editor;
    • add at the end of the file the definition of the new remote:
    [remote "vsts_origin"]
        url = URL_TO_REPO
        fetch = +refs/heads/*:refs/remotes/vsts_origin/*
    

3) Push your local repository mybranch content to the remote repository

  • push your code using the newly create remote by means of executing from command line:

    >git checkout mybranch

    >git push -u vsts_origin mybranch

    This will automatically create the remote branch called mybranch .

Upvotes: 5

Related Questions