I have been using Git lately for my personal projects, and though I am still a noob user, I have been very happy with it. My current client uses TFS, and I have been trying to come up with a way to use Git on top of TFS. This lets me work in a disconnected mode (for example, while working from a coffee shop), while having the ability to commit, branch, view history etc. The speed benefits from having the repository on the local machine rather than accessing it over the network don’t hurt either. Thanks to the excellent Git-Tfs bridge developed by Matt, this was pretty easy to set up. To get started, download the latest version and add the directory that contains git-tfs.exe to your PATH variable.
- Launch Git Bash. If you access TFS from a different account than what you are logged in as, you can launch it under the TFS account by entering the following at Start->Run
runas /netonly /user:your_domain\your_user_name “cmd /c sh –login -i”
(sh.exe resides at “C:\Program Files (x86)\Git\bin” on my computer which is added to the PATH variable.)
Navigate to the directory you want to work in and clone the TFS repository using “git tfs clone repository_url source_path”. You can use the “quick-clone” option if you want just the snapshot of the latest code rather than the complete history. I setup a test project on Codeplex to play with git-tfs, and I had to issue the following command to get the complete repository:
git tfs clone https://tfs.codeplex.com/tfs/tfs24 $/gittfstestNow you can work offline. Add gitignore file to ignore bin directories, temporary files etc, and open your project and make your changes. Visual Studio will warn you on opening the project that TFS is unavailable, since you do not have the code in TFS mapped to this directory. Just choose the “Temporarily work uncontrolled” option.
- You can commit to your local git repository at any time you want. Whenever you are ready to commit back to TFS, you have 3 options:
- git tfs checkin: Allows you to check in code directly into TFS. Can associate the change with commit message, work items etc.
- git tfs checkintool: Allows you to review your changes in the TFS check in tool before checking them in.
3. git tfs shelve: Creates a shelveset that you can review and check in.
- Whenever you are ready to pull the latest code changes from TFS, use
git tfs pull