Create, Connect, and Publish using Visual Studio with Git

Create, Connect, and Publish using Visual Studio with Git

Rate This
  • Comments 28

By: Andy Lewis and Matthew Mitrik (MS)

In the few days since we announced Visual Studio and Team Foundation Service support for Git, it's been exciting to see so much interest, along with a lot of great feedback and questions. We will take your feedback to help us guide how we evolve the tools and the service; so please keep it coming. And as for the questions, we hope that you will find in this post some answers to help you make the most of our Git tools in Visual Studio and our Git service in TFS.

Before we begin, let's recall a key point from Brian Harry:

Both client and server are standard implementations of Git. Our client will work with pretty much any Git repository – local, enterprise, Codeplex, GitHub, BitBucket, …. And TFS will work with pretty much any Git client – existing Git command lines, XCode, Eclipse’s Git support, …. This was a core principle from day 1. This is not about lock in – it’s about providing a good and interoperable Git capability. From Git init VS

In this post we will demonstrate Visual Studio's flexibility to help you get your work done in the places you need to do it: locally, on TFS, or on a third-party service such as those Brian mentions above.

We're here today to help you:

Create new local repositories

One of the key advantages of Git is your ability to do more things locally. Visual Studio provides a few convenient ways to create a local repository:

Create an empty local repository

You just want to create an empty local repository. In Visual Studio you can do this in a few seconds.

Go to the Connect page and create the new repository.

 

Open the repository.  This will set the repo as the active repo in Team Explorer.

Go ahead and commit the default .gitattributes and .gitignore files that Visual Studio created for you. (We'll talk more about these and other Git settings in a future post).

Your new local Git repository is now ready for you to use.

When you are ready, you can publish and share it with your team.

Create a new solution under local Git version control

Whenever you create a new code project, you can put it under local Git version control.

We cover this angle from start to finish in our Welcome Portal tutorial.

Put an existing solution under local Git version control

If you've already got a solution in which you've been tinkering on your local dev machine, before you tinker any further, why not go ahead and add it to a lightweight local Git version control repository?

Now that your repository is created, go ahead and commit your files.

Add an existing local repository

Maybe you've got other repositories you've been using with other client tools. Regardless of whether the local repo has a remote or not, you can add it and then work with it in Visual Studio.  You can add a single repo at a time, or, as we show below, point Visual Studio at a directory that contains multiple repositories and add them all in one shot.

After you add the repository, you can open it and get to work in Visual Studio.

BTW, notice that nifty "Open in Command Prompt" command? Eventually you will likely need it to perform some tasks. If you don't already have command-line tools installed, you can install some:

We'll talk more about common scenarios for using these tools in a future post.

Clone a remote Git repository to your dev machine

Doesn't matter where your Git repository is hosted: TFS, CodePlex, GitHub, Bitbucket, or somewhere else. You can use Visual Studio to work with it. To begin collaborating with others on code in a remote repository, you clone it to your dev machine.

Clone a TFS Git repository to your dev machine

Whether you are new to a team project or just setting up a new dev machine, to get working in a Git team project, clone it to your dev machine.

Clone a third-party Git repository to your dev machine

Does your team have some code in GitHub or another service such as CodePlex or Bitbucket? You can clone the code down to your dev machine and get working in Visual Studio.

Publish your local repository

When you are ready to begin sharing some code on your dev machine with others, you publish the branch to the remote repository.

Publish to TFS

You can publish your code into Team Foundation Service.

Publish to a third-party service

You can publish your branch to a remote repository hosted on a third-party service such as CodePlex, GitHub, or Bitbucket.

 

Did you get the "Branch master does not exist" error? Click here.

After you publish

Having published your branch, Visual Studio has done two things for you:

  • Set the remote of the local repository
  • Pushed your active branch (in most cases this is "master") to the remote repository

After this is done, to collaborate with your team, you can as needed pull their changes and push your changes to the remote repository.

Manage your connections

The Connect page is a new feature in Visual Studio 2012 Update 2. From here you can see and manage all the version control repositories you care about.

Just right-click the repository you want to work and then choose Open or another command.

Tell us what you think

We are experimenting with ways to be more agile and effective in delivering guidance to you. We welcome your feedback not only on our new Git capabilities, but also on the content and format of this post. As we noted above, stay tuned for a few more posts coming on topics such as working with command-line tools, and adjusting Git settings. Thanks for your time and for trying out Visual Studio and TFS with Git!

Leave a Comment
  • Please add 7 and 5 and type the answer here:
  • Post
  • The day I wake up and can do the same I do in Monodevelop in linux and git, with Visual Studio 2013. That day, I will be a happy guy :P

    I think Microsoft has made a good decision supporting git from the IDE but IMO this is a very basic stuff. It is a shame such a powerful developing tool used by million of developers lacks more git integration.

  • @Terry: please submit a bug so we can try to repro and fix the issue: connect.microsoft.com/visualstudio

    @Mauricio: we know we've got more work to do; if you want to propose or vote for specific improvements, I invite you to do so here: visualstudio.uservoice.com

  • "net Error" during publish, no way to repair !

  • The Git support has the following issues

    1) no ssh support

    2) missing all the commands in the ui for merging, branching and managing repositories take a look at what webstorm, eclipse and netbeans do

    3) if  you use a remote mounted share with git it doesn't work

    4) Repository actions don't come up on individual files

    5) Where is compare to remote branch?

  • I tried publishing my local repository into github using VS2013 but I am getting this following error

    An error occurred. Detailed message: An error was raised by libgit2. Category = Unknown (Error).

    No error message has been provided by the native library.

  • Please help me . If any one known how to make internment web browser please send for help me ............thank you

  • I am curious how to manage a solution with multiple projects, each of which is in a different repository.

    For example, a class library we've developed is used by a second class library in most cases, but is and needs to remain versioned independently.  The first class library, as well as the second, are used by a numerous projects (each of which is versioned independently) to interface with servers, etc.  A typical solution would contain a the projects for both of the aforementioned class libraries, as well as a project for the application that will use reference and use them.  

    I'm no git guru, but if I understand correctly, anything that is to be versioned independently, ought to be in its own repository.  Since a typical solution will contain 3 projects, which are all versioned independently, the should come from 3 separate repositories.  

    I'm using github as of now.

    Is this possible in Visual Studio 2013?  Is it simple or convoluted.  It seems it would be a very common scenario.

  • Thanks buddy Hopefulll the git problem solved

  • Hi

    I have a TFS Git project with multiple git repository.

    How can I clone all TFS Git repository to my dev machine?

    When I connect to a TFS project, in the clone repository form the TFS url field seems like readonly.

  • From the SharePoint ALM methodology viewpoint, in your experience guys, TFS or GIT to support the ALM the best?

    Thanks!

  • Why doesn't vs web 2013 have a "remote site" site option to connect to IIS sites that have the old Frontpage extensions?  Is there another way to do this (no, we can't do FTP) If it was intentionally left out, it was a very very stupid idea. Many of us still do simple htm and asp without need of .net or teamserver.  This was available up to VS Express 2012 ... which now crashes with errors making it nearly unusable.    I am actually going to reinstall Frontpage - yes, the old one from > 12 yrs ago ... it still works better for simple pages than all this new overly complex stuff

  • How do you update your password if it has changed on the server?

  • Hi. Thank you for the great article.  I have one big problem with Git in Visual Studio:

    "Using git, how to handle project references when you have projects that are shared across multiple solutions?"

    Imagine the we have a Solution with bunch of Projects under it. And some of the Projects have references to another Project outside of this Solution. TFS manage it very well, but Git doesn't recognize any Project outside of the current Solution. What's the best way to handle it?

    Example: in the following local repository, assume that both SolutionX (in Repos2) and SolutionY (in Repo3) have references to CoreProject (in Repo1, CoreSolution).

    The problem is when you open either SolutionX or SolutionY in Visual Studio, if you change any file in the CoreProject, git doesn't get it! And commit doesn't make any change in Repo1.

    C:\CodeRepos\

     ├ c:\CodeRepos\Repo1\CoreSolution\CoreProject\CoreProject.csproj

     ├ c:\CodeRepos\Repo2\

     │   ├ c:\CodeRepos\Repo2\SolutionX\Project1\Project1.csproj

     │   ├ c:\CodeRepos\Repo2\SolutionX\Project2\Project2.csproj

     │   └ c:\CodeRepos\Repo2\SolutionX\Project3\Project3.csproj

     └ c:\CodeRepos\Repo3\

         ├ c:\CodeRepos\Repo3\SolutionY\ProjectA\Project1.csproj

         └ c:\CodeRepos\Repo3\SolutionY\ProjectB\Project3.csproj

    Also explained here: stackoverflow.com/.../git-and-visual-studio-project-references

Page 2 of 2 (28 items) 12