1

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?

1
  • Have you get the answer which help you solve the problem? If yes, please mark it. And it will help others who have similar questions. Commented May 2, 2017 at 6:42

2 Answers 2

1

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 
Sign up to request clarification or add additional context in comments.

3 Comments

This seems more precise than my answer. +1
Hi, Can you please help with explaining how to implement this vise vera, as in syncing from VSTS git repo to a github repo...
@Jawad In Step 3, select VSTS Git as the Repository and in the powershell script, push changes to GitHub.
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.