Skip to content

Instantly share code, notes, and snippets.

@joefeser
Forked from jschementi/git-tfs.md
Created October 14, 2010 03:25
Show Gist options
  • Save joefeser/625497 to your computer and use it in GitHub Desktop.
Save joefeser/625497 to your computer and use it in GitHub Desktop.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment