# GIT TFS How To ## Intro GitTfs is an addon to GIT that can directly talk to a TFS Servers TFS Projects and both clone, fetch and checkin commits to it. This way, a TFS Project can be GIT cloned into a local GIT repo, a remote GIT repo can be added, and the local repo can be used to move commits between the 3 repos (remote GIT <-> local GIT with GIT TFS <-> TFS You can then automate the transfer of commits between the GIT Server and the TFS Server by calling a simple bat file in intervals that performs a pull/push to GIT and pull/checkin to TFS and in most cases (unless conflicts occur) that should keep the 2 repos in sync automatically. ## Steps (repeat step 6 -> end for updating the repo) - Step 0 Setup VS or TFS Client and GIT for Windows - Step 1 Get GitTfs - https://github.com/git-tfs/git-tfs/releases - Unzip into a local folder (ex: C:\GitTfs) - Unblock all files (use powershell: PS> Get-ChildItem C:\GitTfs -Recurse | Unblock-File) - Add folder to your command prompt PATH (CMD> set PATH=C:\GitTfs;%PATH%) - Step 2 Create a TFS Project (or GIT Project if you start from a TFS Repo) Best done from VS or TFS GUI - Step 3 Clone the TFS Repo using GIT: ```git tfs clone http://n11438:8080/tfs/LoadTestLab $/VSTT-Plugins``` - Step 4 Change directory into your TFS clone ```cd VSTT-Plugins``` - Step 5 Add a GIT Remote ```git remote add gitlab https://git.lightsinline.se/products/VSTT-Plugins.git``` - Step 6 Pull all the latest changes from TFS ```git tfs pull``` - Step 7 Pull from the remote GIT ```git pull gitlab master``` or ```git pull gitlab master --allow-unrelated-histories``` if you already had content in the TFS Repo - If you get merge conflicts, you need to fix them and commit the merge, otherwise you can not checkin to TFS (or vice versa). One easy way to solve conflicts is to use Visual Studio. Add the folder you work in as a local GIT Repo in Team Explorer, open it, goto Sync and it will show you all the conflicts, and you can easely inspect them, choose a side (Remote is the version we dowloaded from before the merge, Local is the version of the files before the remote pull/merge) or do a manual Merge of the code. - Step 8 Checkin to remote TFS ```git status``` should say "nothing to commit, working tree clean" ```git rev-parse HEAD``` to show you the latest commnit id or ```git log``` to show you the latest commits and their messages and finally ```git tfs checkin -m "Sync to Gitlab Commit b617ec73"``` to push the commits to TFS Enter any commit message you find informational (-m above) - Step 9 Push to remote gitlab ```git push gitlab master``` if you had changesets from TFS that you want to push to the gitlab remote Done!