Sync TFS and GIT
Asked Answered
A

2

19

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

Allene answered 21/11, 2013 at 9:54 Comment(0)
S
12

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.
Snap answered 22/11, 2013 at 10:34 Comment(3)
The external parties will create branches in the GIT repository. If I understand you correctly, it is not possible to solve. The secound problem I see is that the GIT repository will not be able to access our TFS server as it is inside the intranet. I want that everything is initiated and coordinated from the TFS server.Allene
Is it any other way we can solve this that works better for us?Allene
No, there is no solution with TFS with what you ask. Your only solution is to migrate away from TFSVC (use a git repository if you have TFS2013 or git repository provider) and sync your 2 git repositories. No other solutions...Snap
K
4

The main change since that question was asked (in Q4 2013) is that TFS 2015/2017 now has an official support for Git repositories. See "Git and TFS".

So a reasonable approach would be to:

  • use a tool like git-tfs to export the existing TFS project history into a new Git repository.
  • split-up that Git repo into one main codebase, and several smaller repos, each one representing the part you want other contributors to access to
  • reference those sub-repos as submodules in the main codebase
  • finally, create TFS projects (this time using Git repos) in order to push back those repos to the TFS server.

That will leave you with a collection of TFS projects, each one can be opened to a particular team, ensuring that only specific parts are visible/accessible to other contributors.

And at any time; from the main coderepo repo, you can update those submodules with:

git submodule update --recursive --remote --rebase

(and then test, add, commit and push: your main Git repo will reference the latest developments from those submodules)

Plus, considering l--''''''---------'''''''''''''s previous question, that would help with a single repo with too many files.
Although, for that, there will be soon(ish) GVFS.


The alternative approach mentioned by l--''''''---------'''''''''''' is:

I personally want to be able to use GIT for my own changes, I would have multiple changesets in GIT, then I would merge them into one, and then convert that changeset into a traditional TFS changeset and check that in, that way I just have 1 check-in per TFS item

That is possible, provided you don't mind losing the intermediate Git commit history, when you will agregate them into one TFS changeset.

Kangaroo answered 18/12, 2017 at 18:43 Comment(8)
thank you very much for this thorough answer. currently we are using tfs 2013. yes, i believe we have the option to create a team project for GIT, but our constraint is that we can't use GIT, we need to use TFS (with TFS, not with GIT) .... however, i personally i want to be able to use GIT for my own changes, i would have multiple changesets in GIT, then i would merge them into one, and then convert that changeset into a traditional TFS changeset and checjk that in, that way i just have 1 check-in per TFS item, makes snese?Dumbfound
@l--''''''---------'''''''''''' I was still editing my answer. Yes, I saw your previous question and TFS 2013. I have edited my answer.Kangaroo
To disambiguate: TFS != TFVC. TFS is the on-premises developer tools product (the on-premises version of VSTS). TFVC is the name of the centralized version control system that originated there. It's hard to parse questions that use "TFS" to mean both.Allusive
@EdwardThomson Thank you. The link I mention (learn.microsoft.com/en-us/vsts/git/overview) is for TFS / VSTS only, right? Not TFVC.Kangaroo
Right, it's for Git in TFS/VSTS. I was mostly looking at l--''''''---------'''''''''''' 's comment, it was especially hard for me to parse "we need to use TFS (with TFS, not with GIT)". I assume that one of those TFS means the version control system (TFVC) and one means the platform (TFS), but I'm a bit confused.Allusive
(I try hard to suppress my pedantry about this, but I find it impossible to avoid complaining when I can't parse the meaning easily.)Allusive
@EdwardThomson I appreciate your pedantry ;) It reminds me of Jon Skeet's (codeblog.jonskeet.uk/2005/12/30/pedantry-how-much-is-too-much)Kangaroo
@EdwardThomson Funny, I do it often and did it today too. And I also do git-tfs and TFS(Git) ;-)Snap

© 2022 - 2024 — McMap. All rights reserved.