Wednesday, July 25, 2012

Git-Tfs Setup And Development Workflow

I finally got around to testing the git-tfs tool. I originally looked at this several months ago and didn't have time to dive into it and WOW was I missing out.

Those That Came Before Me

There are some excellent blogs out there which have plenty of information on this tool, except they all seem to miss the a major issue that none of them address. I will cover them below and the highlights of the installation process.

The Setup

To set it up, just clone the git-tfs GitHub repository. If you use GitHub for Windows, just click the "Clone in Windows" button.

To build the solution, make sure to use the Visual Studio 2010 Command Line, or at least make sure the Visual Studio environment variables are set.
msbuild GitTfs.sln /p:Configuration=Vs2010_Debug
It appears that there is a hidden step that should immediately follow this, copying the output to the Git\bin directory. From the git-tfs directory where the solution file exists, run the following (update accordingly).
copy /Y GitTfs.Vs2010\bin\Debug\*.dll "C:\Program Files (x86)\Git\bin"
copy /Y GitTfs.Vs2010\bin\Debug\*.exe "C:\Program Files (x86)\Git\bin"
Verify that the Git\bin directory is in your path. Open a git bash shell and run:
git tfs help
If the command is found, it is ready to go. At this point a celebration may be appropriate. There is still plenty of awesomeness to come.

The Simple Development Workflow

The workflow for this is actually pretty simple. Git-tfs is only needed in 3 use cases:
  • Clone the project
  • Pulling updates from TFS
  • Pushing files to TFS
Once the project has been cloned, standard git best practices apply. All check-ins to the git repository are stored with the reposiotry.

Getting The Project Files

There are a couple ways to get files out of TFS. You can clone the entire TFS project or just part of it. Performing a quick-clone will generate a git repository with only the latest code (no history). Using clone will generate a git repository with full history. NOTE: in all examples below, omitting <Local Location> will generate the repository in the current directory.

The following is an example of the commands required:
git tfs clone http://vstfs:8080 $/Team.Project <Local Location>

git tfs quick-clone http://vstfs:8080 $/Team.Project <Local Location>
The following are examples of generating a partial repository.
git tfs clone http://vstfs:8080 $/Team.Project/ <Local Location>

git tfs quick-clone http://vstfs:8080 $/Team.Project/ <Local Location>
This can be very useful for instances where a TFS project has multiple root folders like branches, tags, and trunk. It doesn't make a lot of sense to clone the tags unless you have to have it especially if the trunk is needed.

From this point forward, all local changes can be maintained with Git Bash or GitHub for Windows until the repository needs to be updated or changes checked in.

Updating The Repository From TFS

Updating is straight forward. All merging is accomplished with Git's merging functionality and tools.
git tfs pull

Pushing to TFS

Once the changes are complete, use the following to check in the changes. Checking-in to TFS does a rebase, in that it only checks in the latest version and the other check-ins in the git repository are left as is but not persisted in TFS.
git tfs checkin -m "Add a great comment"

That

No comments: