Adding a TFS managed solution to GitHub

Working with VS is quite common to use TFS for our source control. But what if we want to move or just to publish our code on GitHub for other people to view or to contribute? Here is how to do it with just the GitHub website and VS (Visual Studio Tools for Git plugin needed).

1) First of all we need to create a new remote repository for our solution under the GitHub website:

2) With a free GitHub account we can only create a public repository, so basically the only thing we need to specify is the repository name:

3) After the remote repository has been created we can get its link, that is returned for us by GitHub.

4) We can use the link under VS to clone the remote repository (1) to a synchronized local repository folder (2) in our machine:

5) From now on every update we’ll do to our local repository folder will be committable to Git through the VS IDE, the command line or external tools such as SourceTree. Unlike TFS the Git tracking is not related with a specific project file, so every file (even if not included in the solution) will be tracked, compared and synchronized.

What we can do at this point is to copy our solution to the local repository folder. If we open it VS will automatically switch to Git as source control system (even if the solution was associated with TFS) because is able to detect the Git local repository.

If we prefer we can of course remove the TFS association before copying the solution. In this way, if someone will download our code, VS won’t try to connect to our TFS server.

Another option is to create a brand new solution just for Git and to add all the content from the original solution via copy/paste + “Include in Project”.

6) Before committing our local repository to the remote one is a good idea to add a .gitignore file to our solution in order to automatically exclude everything we don’t want to be sent to Git (the /bin folder for instance). Of course we could specify every time what to include and what not to include as we do in TFS, but in this way it will be easier and quicker and we’ll be sure that we’ll be always applying the same rules. We can ask Visual Studio to generate this file for us, with all the necessary configuration already included. Here is what to do in order to add it to the solution.

After added this file we can commit while including everything (with the “Include All” command) being sure that all the files referred by the .gitignore will be excluded anyway.

7) When we are happy with the solution we have in our local repository folder we can commit it to the remote one. To do this we first use the “commit” command to commit the changes we did in our local repository folder to the local repository. Then we use the “push” (first time) and “sync” commands to synchronize our local repository with the remote one:

8) Finally we can see our solution on GitHub:

Is a good practice to add a file to the GitHub repository. This file will be automatically displayed in the repository’s page and can be used to contain a short description/guide about the project.