Once you start using Git for version control you never want to go back to the old centralized version control model of tools like TFS. But what if you are stuck with TFS for some reason and can't move your code to a Git repo?
Git-TF to the Rescue
With the cross-platform Git-TF tools, you can use Git to work with TFS. A couple simple commands provided by Git-TF allow you to push your Git commits as TFS check-ins, pull the latest code from TFS into your Git repo, etc.
One of the nice side benefits of syncing your Git repo with a TFS folder is that you can organize your code in whatever local folder structure you wish. With a typical TFS-based project, your local folders must match the structure defined in the central TFS location. But with Git-TF, you can hook up your local Git repo folder to whatever TFS central folder or sub-folder you wish to synch with.
Here are the Git-TF commands that you'll want to learn.
For initial setup of a Git repo based on a folder in TFS, run a command like the following.
git tf clone https://yourproject.visualstudio.com/DefaultCollection $/YourRepo/SubFolder repo
That command should be run with your current working directory set to the parent folder for your new, local Git repo. And in this example, the subfolder
repo is being created. The TFS folder to which you are mapping is indicated with the opening dollar sign, which in this example is
After that initial setup is out of the way, change your working directory into the subfolder you just created. For example:
And now you may want to configure your TFS username and password so that you won't be prompted for them every time you issue a command.
git config git-tf.server.username YourUsernameOrEmail
git config git-tf.server.password YourPassword
Now you make your changes to the files in your local Git repo and commit them locally as needed.
git add --all . git commit -am "commit one"
git add --all . git commit -am "commit two"
Finally, you sync your local changes and any remote TFS changes made by others with these two commands:
git tf pull --rebase git tf checkin
That's it for the typical workflow. Rinse and repeat the last 4 commands (
I'd recommend creating a batch script in your local repo folder (call it
tf-checkin.bat for example) that prompts for your commit message and executes all of the commands. Here's an example:
@echo off SET /P CM=Enter Commit Message: git add --all . git commit -am "%CM%" git tf pull --rebase git tf checkin
TFS Online and SSL
When syncing with a TFS Online project, Git-TF will be hitting an SSL connection. Under the hood, Git-TF uses Java, so you may need to configure Java to use your org's SSL certificate. Here's an example of the command to do that.
"C:\Program Files\Java\jre1.8.0_51\bin\keytool" -import -keystore "C:\Program Files\Java\jre1.8.0_51\lib\security\cacerts" -alias startssl -file "M:\My Org Cert\MyOrg-CA.cer"
I was prompted to enter a password for the keystore. The default password is: changeit
Note that the paths in the example command above will be different depending on the version of Java installed on your system. In the example above, the version 1.8.0_51 is referenced in two places.
Git and SSL
Git itself may also complain that you have a "self signed certificate in certificate chain". If that happens, run the following command too.
git config --global http.sslVerify false
I think you'll find that investing a little time to learn Git and use Git-TF for code located in TFS will save you a lot of time and frustration down the road.