Skip to content

Instantly share code, notes, and snippets.

@jschementi
Created January 26, 2010 08:35
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save jschementi/286677 to your computer and use it in GitHub Desktop.
Save jschementi/286677 to your computer and use it in GitHub Desktop.
Using TFS and GIT together

Using TFS and GIT together

What if your team uses TFS, but you want offline support? You can have a Git repo as well, but then getting your changes to TFS is burdensome. Here’s where a GIT to TFS bridge would be handy.

Setting up your repo

Here’s how to keep a TFS repository foo, and a GIT repository bar, in sync. First step is you need to create a new TFS workspace:

cd \
tf workspace /new /noprompt Foo

Now you should place your .git folder from the root of your git repo in the root of your TFS repo. If you don’t have the git repo locally, you can get it like this:

cd \temp
git clone git@github.com:yourusername/yourgitrepo.git
cd yourgitrepo
copy .git \Foo
rmdir /S yourgitrepo

Then you’ll want to sync the TFS repo up with what was in the GIT repo

cd \Foo
git reset –hard

Or if you want to do the other-way around:

cd \Foo
tf get /overwrite

At this point you should have no pending changes from either TFS or GIT.

Work in git, push to TFS

If you want to do some work in GIT, and then eventually push to TFS, here’s how you’d do it:

First, make sure TFS is updated:

tf get /overwrite

Next, make sure your GIT code is updated:

git pull

Tell TFS about all the git changes

tfpt online . /recursive /adds /deletes /diff

Make a shelveset with all the pending changes

tf shelve

Run whatever command executes your tests, and checks in the code

Pull from TFS into GIT

Let’s say someone has checked in something into TFS which you want in GIT.

Make sure git is updated:

git pull

Overwrite your git repo with TFS:

tf get /overwrite

As that runs, you’ll see a list of files coming in. Now you need to tell git about them:

git add .

Now, commit that to git:

git commit -a -m “Sync to head of TFS”

Run all your tests, and if they pass, push it out to the remote repo:

git push
@ferventcoder
Copy link

@jschementi
Copy link
Author

Yep, not sure if that was around at the time, but thanks for the pointer!

Copy link

ghost commented Mar 21, 2016

Thank you, good article.
git-tfs is for Windows users. I want to share a code base between Linux and Windows. I think I can make that working based on this.

Copy link

ghost commented Feb 14, 2017

Is it possible to run "tfpt online . /recursive /adds /deletes /diff" on Linux?
I am using git on Linux and need to publish source code without history to TFS (each check-in is one release version).

tf is available here: https://github.com/Microsoft/team-explorer-everywhere

But how to get tfpt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment