Create New Folder Hierarchies For TFS Projects using Git SCM

Published on
Reading time
Authors

If, like a lot of people who've worked heavily with TFS you may not have spent much time working with Git or any of its DVCS bretheren.

Firstly, a few key things:

  1. Read and absorb the tutorial on how best to work with Git from the folks over at Atlassian. http://atlassian.com/git/tutorial/git-basics

  2. Install the Visual Studio 2012 Update 2 (currently in CTP, possibly in RTM by the time you read this). http://www.microsoft.com/en-us/download/details.aspx?id=36539 (grab just vsupdate_KB2707250.exe)

  3. Install the Git Tools for Visual Studio http://visualstudiogallery.msdn.microsoft.com/abafc7d6-dcaa-40f4-8a5e-d6724bdb980c

  4. Install the most recent Git client software from http://git-scm.com/downloads

  5. Set your default Visual Studio Source Control provider to be "Microsoft Git Provider".

  6. Setup an account on Team Foundation Service (https://tfs.visualstudio.com/), or if you're lucky enough maybe you can even do this with your on-premise TFS instance now...

  7. Make sure you enable and set alternative credentials in your TFS profile:

alt-credentials
  1. Setup a project that uses Git for source control.

At this stage you have a couple of options - you can clone the repository using Visual Studio's Git support

gitclone

OR you can do it right from the commandline using the standard Git tooling (make sure you're at a good location on disk when you run this command):

git clone https://thesimpsons.visualstudio.com/defaultcollection/_git/bart milhouse

Cloning into 'milhouse'...

Username for 'https://thesimpsons.visualstudio.com/': homer
Password for 'https://thesimpsons.visualstudio.com/':

Warning: You appear to have cloned an empty repository.

I tend to setup a project directory hierarchy early on and with Git support in Visual Studio I'd say it's even more important as you don't have a Source Control Explorer view of the world and Visual Studio can quickly create a mess when adding lots of projects or solution elements.  The challenge is that (as of writing) Git won't support empty folders and the easiest work around is to create your folder structure and drop an empty file into each folder.

Now this is where Visual Studio's Git tools won't help you - they have no concept of files / folders held outside of Visual Studio solutions so you will need to use the Git tools at the commandline to affect this change. Once have your hierarchy setup with empty files in each folder, at a command prompt change into the root of your local repository and then do the following.

git add -A
git commit -m "Hmmmm donuts."

Now, at this point, if you issue "git push" you may experience a problem and receive this message:

No refs in common and none specified; doing nothing. Perhaps you should specify a branch such as 'master'. Everything up-to-date.

Which apart from being pretty good english (if we ignore 'refs') is pretty damn useless.

How to fix? Like this:

git push origin master

This will perform a forced push and your newly populated hierachy should be pushed to TFS, er Git, er TFS. You get the idea. Then the others on your team are able to clone the repository (or perform a pull) and will receive the updates.

HTH.

Update: A big gotcha that I've found, and it results in a subtle issue is this: if you have a project that has spaces in its title (i.e. "Big Web") then Git happily URL encodes that and will write the folder to disk in the form "Big%20Web" which is all fine and dandy until you try to compile anything in Visual Studio. Then you'll start getting CS0006 compilation errors (unable to find metadata files).  The fix is to override the target when cloning the repository to make sure the folder is validly named (in my example above this clones the "bart" project to the local "milhouse" folder).