Visual Studio Team Services - Sync w/ Github Repos

2020-07-30 03:50发布

问题:

I'm attempting to set my company up with a Visual Studio Team Services repository, and sync it with a private Github repo. There are only a handful of us that work on the tech side, but some like to use VSTS and some like to use Github. The documentation everywhere says that you can sync the two. That way changes made in Github will show up in Visual Studio Online, and vice-versa. I'm learning that's easier said than done.

I've attempted to follow the directions provided by Microsoft, and have not found any solutions to my problem. I can clone the existing Github repo easily enough, but changes there don't sync to the VSTS repo.

I tried the following instructions as well: How to synchronize VSTS and Github respositories when commits are made The build passes, and it even shows what commits it has picked up. However new files and/or any changes do not appear in the VSTS repo at all.

Can someone please help??

回答1:

Simple way to sync VSTS repo from Github repo.

  1. Add GitHub service endpoint to your VSTS (Setting > Service)
  2. Create an Empty build definition with GitHub repository in your VSTS
  3. Select Repository tab and specify Connection, Repository and Default branch. (set Clean to true if necessary)
  4. Select Triggers tab and check Continuous integration, Batch changes and specify Branch filters
  5. Select Options tab and check Allow Scripts to Access OAuth Token
  6. Select Build tab and add Command Line step/task (Tool: [Git tool path]; Arguments: push https://$(System.AccessToken)@[xxx].visualstudio.com/[teamproject]/_git/[repo name] HEAD:[branch]; Working folder: $(Build.SourcesDirectory)


回答2:

You can do it all in the same directory by adding a second remote origin, if you've already added VSTS as 'origin', then run:

git remote add github https://github.com/user/repo.git

then you can push up your changes you've made to the two repos

to push to VSTS:

git push origin

and then to push to GitHub

git push github

See this github doc page

If you wanted to automate this you might want to set it up as a scheduled task on a machine, or you can get it connected to git hooks on VSTS?



回答3:

Actually you can use "Git Mirror" from marketplace.

https://marketplace.visualstudio.com/items?itemName=nobitagamer.gitmirror