18 June 2016

TFS with Git: Using a Local Git Repo with TFS

Using Git With TFVC
If is possible to use a local git repo with TFVC using [Git-TF](http://gittf.codeplex.com/).

NB: All operations are done in the command line (cmd.exe) as admin.


1. Java runtime Environment: http://java.com/en/download/manual.jsp
   or choco install javaruntime
2. Add Java to PATH Environment variable e.g.  
   setx /M path "%path%;C:\Program Files (x86)\Java\jre1.8.0_91\bin"
3. Install [gittf](http://gittf.codeplex.com/) to C:\git-tf
   coco install git-tf

Clone a Branch

1. Make a parent directory for your repo and cd into it e.g.  
   C:\Dev\Git\[Project Name]\Development
2. Clone a branch e.g.  
   "C:\Users\All Users\chocolatey\lib\Git-TF\Tools\git-tf-\git-tf"  clone https://[TFS domain]/tfs/[Project Collection] "$/[TFS Path]"

Checkin changes to your local repo

Check in to your local git repo as you would normally with an associated work item and comment.
This is best done in VStudio (to ensure you have an associated work item)

It can be done on the command line or using a third party tool e.g.

Forward Integrate TFVC branch > local git repo

  • cd to the directory e.g.
    cd C:\Dev\Git\[Project Name]\Main
  • Pull:
    git-tf pull
  • Rebase:
    git-tf pull --rebase

Checkin your changes to TFVC

NB: git-tf will include author etc by default so you probably want to turn that off:
git-tf configure --no-metadata
  • Pull first:
      git-tf pull  
  • Checkin and associate a work item (--deep creates a TFS checkin for each git commit):
    git-tf checkin --deep --associate=[workitem id]

Add a Remote Git Repo

You may want to add an alternative Git repo to checkin against:
  • List remotes:git remote -v
  • Add a new one: git remote add <shortname> <url>

Suggested workflow:

git checkout -b taskXXX  
git commit  
git commit...  

git checkout master  
git-tf pull --rebase  
git merge --squash taskXXX  
git commit  

git-tf checkin --associate=X  

More Information

  • Atlassian Git Tutorial: https://www.atlassian.com/git/tutorials/setting-up-a-repository

No comments:

Post a Comment