A few months ago, in conjunction with the release of Visual Studio 2012, Microsoft also released a hosted TFSÂ (Note: this hosted service is called Team Foundation Service; Team Foundation Server is the thing you install onsite. Â I’m going to call Team Foundation Service “hosted TFS” for brevity and clarity).Â This is kind of the third version of hosted TFS, which in Microsoft-land means itâ€™s pretty good.Â True to form, VS 2012 is pretty good, and in contrast to previous versions has a good focus on agile teams.Â Iâ€™ve had the opportunity to use this for well over a year now, and Iâ€™ve seen hosted TFS grow into something you need to look at before you deride it.Â A wise move on Microsoftâ€™s part is that hosted TFS is free for teams up to five, so you can explore and use at no cost.
Perhaps the greatest downside to TFS is that you were completely locked in to the TFS version control methods.Â The displeasures with this were great in number.Â Git, especially Githubâ€™s implementation, gained popularity in enterprises because of its distributed nature and ease of collaboration.Â Microsoftâ€™s first foray to combining the features of Git and TFS was git-tf, which presented a git-like overlay onto TFS repositories.
Just this past week Microsoft dropped the bombshell that Git was a first class choice for version control in hosted TFS (readÂ Team Foundation Service updates â€“ Jan 30Â or watchÂ Git Support Added to Visual Studio and TFS).Â Woah.Â All the planning and tracking features of TFS (including the scrumboards) and the DVCS workflow of Git, in one offering. Â Right now, Git is a feature in hosted TFS only; it’s planned for TFS but no timetable has been announced.
Also released was the CTP of Visual Studio 2012 Update 2 (VS2012.2) (see also Git init VS), which adds git support directly into Visual Studio 2012.Â
Warningâ€”do not install this update if you have existing TFS repos.Â There are several reports of it corrupting existing TFS repos.Â You might want to sit this one out, and keep your eyes peeled for a future version that wonâ€™t kill your existing repos.Â Stay tuned for updates and more information.Â This will be fixed soon, Iâ€™m sure.Â In the case of my team at the day job, we are connecting to TFS 2008 with VS 2012, which is not a supported scenario (even though it seems to work fine for us). Â This is a known issue, see the compatibility matrix atÂ Compatibility between Team Foundation Clients and Team Foundation Server. Â If you’re using TFS 2008 or earlier, skip this update. Â Otherwise, you’re apparently fine.
Using Git in Hosted TFS
For more information on using Git in TFS with VS 2012, see Getting Started with Git in Visual Studio and Team Foundation Service, or the hosted TFS docs at Visual Studio with Git.Â I have not installed the update, so Iâ€™m going to use Bash for this walkthrough.
Your Windows Live Id canâ€™t be used by VS or any of the other tools, so you have to create an alternate credential first.Â Once youâ€™ve logged in, click on your user name in the upper-right corner and choose â€œMy Profileâ€:
Then select the Credentials tab, and click on â€œEnable alternate credentialsâ€
Enter a secondary user name and a passwordâ€”only one is allowed per account.
Youâ€™ll enter these credentials a little later when you clone the repo.
Next, create a new Team Project with Git:
Give a name, a description, a Process template (project tracking style), and choose Git as your version control.Â (Note: As I later found out, donâ€™t put spaces in repo names. Not only is %20 a pain to remember and type, but VS appears to get confused with where it put the Nuget packages. I kept getting all kinds of errors when trying to build the project. Fortunately, it was a demo only.)
TFS will then create your project (they are certainly optimistic!):
If this is a new project, create a folder where you want the project files to be.Â If you have an existing project, you can work with that, no problem.Â Either way, open Git bash and navigate to your working folder.Â To clone a new project, issue the following command:
git clone https://<accountname>.visualstudio.com/defaultcollection/_git/<repo>
A couple things to noteâ€”since this is a URL, remember to HTML encode the repo name if you have spaces (e.g., repo%20name).Â Also, TFS projects are arranged into collections.Â If you havenâ€™t created a collection, use defaultcollection in the path.Â If youâ€™ve created a collection, use that.Â If you have an existing repo, use git init rather than git clone.Â Youâ€™ll be prompted for a username and password, and this is where you enter the secondary credentials you created earlier.
Now letâ€™s see how this all works.Â Open up Visual Studio and create a new project in the folder you cloned into.Â Once the project is created, switch back to Bash and list the files.Â You can see youâ€™re working in the master branch.Â A status check shows your new files.
If you try to add your files, and get an error like below, there is a simple fix:
You probably need to change the handling of LF and CRLF; check this with git config core.autocrlf.Â True means that line endings will be changed on commit/checkout.Â What you do depends on the systems your team members are using; there is a good discussion at http://kernel.org/pub/software/scm/git/docs/git-config.html.Â If everyone is using Windows, you can set this to false and line endings will remain unchanged.
Add your new files and commit them.Â If youâ€™re new to Git, this commit will save the new files in the local copy of the repository.Â Now, you can push the files to your repo:
Looking back in TFS, this is how we see the repo:
Letâ€™s take a look at something basicâ€”branching.Â Create a branch (I called mine sprint1), then make a small change to a file.Â Commit the changes, and push to TFS (remember to use git push origin sprint1).
Looking back in TFS, we switch branches with a dropdown list on the far right:
After switching branches, you can select the history tab and see the history of the branch.
Clicking on the message for one of the commits brings up the commit changes:
Drilling down in the Source Explorer to the file where you made the change, you can choose the compare tab and see the diff between commits.
This view can also be changed into an inline view:
Conflicts are resolved locally, before pushing to the repo.Â You do this in whatever client or tool youâ€™re using.
TFS vs. Github â€“ a comparison
In the table below, Iâ€™ve attempted to compare the major features between Github and Git in TFS.Â Itâ€™s far from complete, and Iâ€™ll happily make corrections or add more comparisons if you leave a comment.Â Iâ€™m a light user of Github, I actually use Bitbucket for my side projects.
||Hosted TFS w/ Git
||No, changes are published directly to the repo
||No, nothing similar
|Work item/bug tracking
||Git Bash (and clients based on CLI, such as TortoiseGit), github:windows, Eclipse plugin, VS 2012 (with Git updates)
||VS 2012 (with Git updates),Â Team Explorer Everywhere (Eclipse plugin and cross-platform CLI), Git Bash (and clients based on the CLI, such as TortoiseGit)
||Unlimited, free for teams up to 5
||None, not meant for public repos
If youâ€™d like more information about Git, check out Syncfusionâ€™s free Git Succinctly, or Oâ€™Reillyâ€™s Version Control with Git.
The addition of Git to TFS as a source control option is very exciting.Â If youâ€™re used to the way Github or Bitbucket implements Git, you might find this implementation lacking a couple of your favorite features, even though the TFS implementation has all of Gitâ€™s features.Â This may or may not be a deal breaker for you.Â That you can use either VS or Eclipse or Bash or other Git tools is great, and that users on any OS can use TFS.