Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use git-tfs and idiomatic git branching against a TFS repository?

How Do I Use git-tfs Idiomatically?

  • The git idiom is to check out branches to the root directory of the repository. Checking out a branch will replace the contents of the directory with the contents of that branch.

  • The TFS idiom is to check out each branch in a different directory under the root directory of the repository (even the master or trunk branch). Checking out a branch will place it in a new directory next to the current one.

Using git-tfs, I can clone a TFS repository or branch into a git repository. I want to work on a TFS repository with multiple branches in a manner consistent with the git branching idiom. But I'm not sure what's technically possible or recommended :)


Clone The Whole TFS Repository

If I clone the whole repository out of TFS

> git tfs clone http://<tfsurl>:8080 $/main 

That would give me a git master containing all the TFS branches as directories.

[master]> dir   trunk   feature-logon   feature-search   release-0.0.1 

Add a Remote Per TFS Branch

I don't know if I can (or how to) map a git remote to each TFS branch.

> git init . [master]> git tfs clone http://<url> $/main/trunk . 

Then

[master]> git checkout -b feature-logon [feature-logon]> git tfs clone http://<url> $/main/feature-logon . 

I know this is technically incorrect, but I don't know any better without playing (my only TFS repo is very large, experimenting is taking a long time)

like image 618
Anthony Mastrean Avatar asked Feb 26 '11 21:02

Anthony Mastrean


People also ask

Does TFS use git?

Git in Visual Studio, Azure DevOps Services, and TFS is standard Git. You can use Visual Studio with third-party Git services, and you can also use third-party Git clients with TFS. To learn more, see Git and Azure Repos.

Can we use git to clone from TFS?

You can clone all projects by specifying $/ as the tfs-repository path. If you do not specify a git repository name, it will clone into tfs-collection .

How do I get git TFS?

Extract the ZIP file, and add the resulting directory to your PATH environment variable. Verify that git-tfs is installed correctly by opening a new command prompt and type git tfs --version. The source code is available on GitHub. Start by cloning your TFS project into a Git repository.


1 Answers

It's now possible to get the TFS branches to be correct Git branches if cloning using git-tfs. This is now in the stable release! You first clone not the entire repository but the trunk :

git tfs clone http://<tfsurl>:8080 $/main/trunk 

Then you run branch --init, which creates a new branch in the Git repository

git tfs branch --init $/MyProject/MyTFSBranch 

in your case :

git tfs branch --init $/main/feature-logon 

Or use the the --all flag on a fresh cloned repository to create ALL the branches present on the TFS server.

git tfs branch --init --all 

You could also clone directly with all the branches using flag --with-branches:

git tfs clone http://<tfsurl>:8080 $/main/trunk --with-branches 

The documentation for this new command is here. Feel free to provide feedback to improve it...

like image 101
riper Avatar answered Oct 08 '22 13:10

riper