How to manage two TFS projects in one git repository?
Asked Answered
O

2

4

We are using TFS as main source control and I would like to use git as a "frontend" together with git-tfs rcheckin command but I have problems importing my repositories into git.

I have a two projects in my TFS

$/ProjectA
$/ProjectB

and I would like to manage them in one git repository.

How I can clone those two into one git repository so I can commit and push changes to both projects as one TFS changeset?

I tried using git tfs subtree but somehow I cannot figure out workflow with this. My approach was to init git repo like shown below but I got errors I cannot recover from:

> git init
Initialized empty Git repository in c:/somedir/.git/

> git tfs subtree add --prefix=ProjectA  http://tfs_server:8080/tfs/ $/ProjectA
executing subtree add
-> new owning remote default
-> new remote default_subtree/ProjectA
Fetching from TFS remote 'default_subtree/ProjectA'...
C3779 = 7e532464ef6120ac0b19aa3c7651ceae915dc366
C3780 = 16f4636fc53d729767f65213ed047c11d1a707ee
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
error running command: git subtree add --prefix=ProjectA "-m Add 'ProjectA/' from commit '16f4636fc53d729767f65213ed047c11d1a707ee'

git-tfs-id: [http://tfs_server:8080/tfs/];C3780" refs/remotes/tfs/default_subtree/ProjectA
Command exited with error code: 1
Oldest answered 17/9, 2014 at 8:44 Comment(2)
Another approach could be the use of SubModules instead. You'd end up with 3 Git Repo's one for each project and one that hosts them both as sub modules.Fluoroscopy
@Fluoroscopy But than I need to synchronize manually each module. And I think I cannot commit to TFS changes from multiple projects as one TFS changeset.Oldest
D
2

I had the same problem, but a part of this answer pointed me to the right direction.

> git init
Initialized empty Git repository in c:/somedir/.git/

> git tfs subtree add --prefix=ProjectA  http://tfs_server:8080/tfs/ $/ProjectA
....
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
....

This error probably comes from git diff-index HEAD command. When I try it, I get exactly the same message.

The problem here is that .. there is no HEAD yet. The repository is empty. The master branch has no commits, hence, no head. Just add a dummy commit and then try running git tfs subtree add ... and it will work fine.

git init
touch foo
git add foo
git commit -m "dummy commit to get a HEAD on master"
git tfs subtree add --prefix=AAA tfsurl $/path/to/AAA
git tfs subtree add --prefix=BBB tfsurl $/path/to/different/BBB

My local repo was empty like in your case and this small trick just solved the ambiguous argument 'HEAD' error for me on git 2.7.1.windows.2 using git-tfs 0.25.0.0 (TFS client library 14.0)

EDIT: Ohh, and be sure to invoke all git tfs commands in a Windows Command Prompt. At least in the git/gittfs versions I use, git-tfs-subtree does not work properly when invoked from a git-bash console and it messes up some paths and refspecs.

Dispersal answered 28/6, 2016 at 16:14 Comment(0)
D
1

If you are using Git on TFS:

The easiest way to do this is to simply check out each project and add the files to a single Git repository.

If you are using TFVC on TFS:

There is no way to do this. You can clone each repo separately and work on them independently. You cant have two different branching structures in a single Git repo.

If you are using TFVC with no branches:

You can use the GitTF subtree feature to have a single Git repo that contains two independent synched folders from TFVC.

I would recommend that you migrate permanently to Git.

Damascene answered 20/9, 2014 at 13:56 Comment(6)
I was considering it but I need whole history and I would like to commit from multiple projects as one TFS changeset.Oldest
You can take history with Git-TF for each project and create separate Repositories with the History. You should then be able to merge the repos.Damascene
But once I merge repos than it will be not possible to push to TFS again, won't it?Oldest
You need to be using Git on the TFS side. This will not work with TFVC.Damascene
Why wouldn't it work on non-Git TFS? Wouldn't git tfs clone work on it? I may be wrong, but I'm pretty sure it just cloned a tfs repo for me, and my TFS instance it's not based on Git, so it's probably plan MS TFS repo. git tfs subtree seems to work too. Could you explain what you meant?Dispersal
You cant have two different branching structures from two different TFVC projects coexist in the same Git repo. You would need two repos,or the same branch instances for both folder structures.Damascene

© 2022 - 2024 — McMap. All rights reserved.