Karthik Rajasekaran
Karthik Rajasekaran

Reputation: 13

Sync Git repository with the Git Integrated in VSTS

I would like to know is there any way we can sync the Git repository with the Git Integrated with VSTS. For example, say I have a Git repository "https://github.com/test/TestProject" and I have imported this Git repo in VSTS. Now my VSTS Git repository URL say "https://testuser.visualstudio.com/test/_git/TestProject".

I want to sync these two things and keep always updated. Like If I'm making any changes in the direct Git repo, it should reflect in the VSTS Git repository. Even if it's through any build definitions or any pull request, its fine.

Can someone help me in this?

Upvotes: 1

Views: 977

Answers (2)

Eddie Chen - MSFT
Eddie Chen - MSFT

Reputation: 29966

It could be also achieved by creating a build definition to pull the changes from GitHub and then push the changes to VSTS Git. Following are the steps for your reference:

  1. Deploy your own build agent and then generate a SSH Key.
  2. Enable SSH Authentication for your VSTS Git Repo so that you don't need to enter username and password in your build definition. If you want to use alternative credentials, you can skip Step 1 and Step 2.
  3. Create a build definition and select GitHub as the Repository.
  4. Enable "Continuous integration (CI)" option in the build definition so that the build will be triggered as soon as new changes committed in GitHub.
  5. Add a PowerShell script in your build definition to add VSTS Git as remote and push changes to it.

Now you should see a build been triggered when you commit a change in GitHub and then build will pull the changes from GitHub and push it to VSTS Git. enter image description here PowerShell code for your reference:

git remote add vstsg ssh://[email protected]:22/VSTSProjectName/_git/VSTSGitRepoName  2>&1 | Write-Host

git checkout -b master  2>&1 | Write-Host

git push vstsg master  2>&1 | Write-Host

Upvotes: 1

VonC
VonC

Reputation: 1324228

You need to have a webhook (ion GitHub) or a service hook (on Visual Studio) in order to receive a push event.

You also need to write and install a listener which would listen for that push event as sent by the web/service hook as a JSON payload (See the GitHub one, or the Visual Studio one).
Visual Studio integrates with external services as well, which have their own listener.

On receiving the push event from one remote repo, you can then pull from it, and push to the other. But note that any concurrent development on the same branch would potentially result in a conflict when pushing from one repo to the other. This approach works when differents branches are used on each repo.

Upvotes: 0

Related Questions