Sync TFS and GIT

magol picture magol · Nov 21, 2013 · Viewed 9.6k times · Source

Today we have all our source code on our local TFS server. Now we want that some external parties can access a portion of the code. We therefore looking at the possibility that e.g. Clone this code to an external GIT server they can access.

I have looked at the git-tfs. But if I understand correctly, you have to manually synchronize GIT and TFS when it happened changes on any of them. Is there a way to have a clone of the code that is automatically synced.

If there are changes in TFS, it is automatically synced to GIT, and vice versa. There should be no uncertainty if I work with the most current code

Answer

Philippe picture Philippe · Nov 22, 2013

There is no way to sync 2 repositories evolving separatly 100% automaticaly with whatever solution you choose (to achieve automatic sync, you must either achieve a sync in no time or being able to block push in git or check in in TFVC when one of the 2 team begin a sync) .

So, you will always have conflicts that you should merge manualy. You could find a workflow that will prevent most of them but never solve all the cases and these remaining cases will be really difficult to solve...

Anyway, you could nearly achived what you want (it depends of your expectations : do you need branching support --hard--,...) with git-tfs (I have included in git-tfs all needed to do that but never used in production) but it's a little bit tricky.

You need to clone your TFS repository in a bare repository :

git tfs clone https://server/tfs/TeamCollection $/project/trunk --bare --with-branches

then you need to write in your post-receive hook of this bare repository something like that (I do not remember if it works) :

branch=$(git rev-parse --symbolic --abbrev-ref $1)
if [ "master" == "$branch" ]; then
    branch="default" 
fi
git tfs rcheckin --bare -i $branch

With that, every time someone push in the git repository, the commits will be checked in in TFS.

For more comfort (otherwise they will always have boring conflicts to solve when they try to push), you could sync git repository with TFS server with a scheduled task with the command (this way they will be aware of new commits sooner) :

git tfs fetch --all

Note : I don't remember if this command could be used in a bare repository (now that I think about that, I don't think so). Otherwise you will have to use instead git tfs fetch -b=myGitBranch -i tfsRemote for each existing branch :(

But I'm sure they will never be able to work with branches that was not already created in tfs :( The git-tfs tool is indeed not able to create automatically a TFVC branch from a git history. Technically, that's achievable, I think, but never developed (because git-tfs is more à tool to run away of TFVC than a tool to check your development in it... )

And some other stuff could be difficult or impossible to do...

I hope it will help.

PS :

  • that's a hard job you are trying to do for someone not used to git-tfs...and something I don't recommend to do.
  • I highly recommend to go the same way Microsoft is taking and to migrate everything on git (even staying on TFS server or VSTS if needed), that way the sync will be a lot easier (even if not 100% automatic ;-)). I have made a good doc on how to migrate from TFVC: https://github.com/git-tfs/git-tfs/blob/master/doc/usecases/migrate_tfs_to_git.md
  • Try to convince your enterprise that each team should choose and master its tools and not be imposed some choices.