{"id":9718,"date":"2013-02-06T09:12:00","date_gmt":"2013-02-06T09:12:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2013\/02\/06\/create-connect-and-publish-using-visual-studio-with-git\/"},"modified":"2019-02-14T17:57:37","modified_gmt":"2019-02-15T01:57:37","slug":"create-connect-and-publish-using-visual-studio-with-git-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/create-connect-and-publish-using-visual-studio-with-git-2\/","title":{"rendered":"Create, Connect, and Publish using Visual Studio with Git"},"content":{"rendered":"<p>\/\/ \n&lt;!&#8211;<\/p>\n<h1 class=\"header-title\">Create, Connect, and Publish using Visual Studio with Git<\/h2>\n<p>&#8211;&gt;<\/p>\n<p>By: <a href=\"http:\/\/social.msdn.microsoft.com\/profile\/andy%20lewis%20-%20msft\/\">Andy Lewis<\/a> and <a href=\"http:\/\/social.msdn.microsoft.com\/profile\/matthew%20mitrik%20(ms)\/\">Matthew Mitrik (MS)<\/a><\/p>\n<p>In the few days since we announced <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2013\/01\/30\/getting-started-with-git-in-visual-studio-and-team-foundation-service.aspx\">Visual Studio and Team Foundation Service support for Git<\/a>, it&#8217;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.<\/p>\n<p>Before we begin, let&#8217;s recall a key point from <a href=\"http:\/\/blogs.msdn.com\/b\/bharry\/\">Brian Harry<\/a>:<\/p>\n<div style=\"background-color: #eed2ee;margin: 3px 3px 5px 15px;padding: 1px 10px 1px 10px\">\n<p>Both client and server are standard implementations of Git. Our client will work with pretty much any Git repository &ndash; local, enterprise, Codeplex, GitHub, BitBucket, &hellip;. And TFS will work with pretty much any Git client &ndash; existing Git command lines, XCode, Eclipse&rsquo;s Git support, &hellip;. This was a core principle from day 1. This is not about lock in &ndash; it&rsquo;s about providing a good and interoperable Git capability. From <a href=\"http:\/\/blogs.msdn.com\/b\/bharry\/archive\/2013\/01\/30\/git-init-vs.aspx\">Git init VS<\/a><\/p>\n<\/div>\n<p>In this post we will demonstrate Visual Studio&#8217;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.<\/p>\n<p><strong>We&#8217;re here today to help you:<\/strong><\/p>\n<ul>\n<li><a href=\"#create-local\">Create new local repositories<\/a>\n<ul>\n<li><a href=\"#create-local-empty\">Create an empty local repository<\/a><\/li>\n<li><a href=\"#create-local-solution-new\">Create a new solution under local Git version control<\/a><\/li>\n<li><a href=\"#create-local-solution-exists\">Put an existing solution under local Git version control<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#add\">Add an existing local repository<\/a><\/li>\n<li><a href=\"#clone\">Clone a remote Git repository to your dev machine<\/a>\n<ul>\n<li><a href=\"#clone-tfs\">Clone a TFS Git repository to your dev machine<\/a><\/li>\n<li><a href=\"#clone-3rd-party\">Clone a third-party Git repository to your dev machine<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#publish\">Publish your local repository<\/a>\n<ul>\n<li><a href=\"#publish-tfs\">Publish to TFS<\/a><\/li>\n<li><a href=\"#publish-3rd-party\">Publish to a third-party service<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#connect\">Manage your connections<\/a><\/li>\n<li><a href=\"#feedback\">Tell us what you think<\/a><\/li>\n<\/ul>\n<h2><a name=\"create-local\"><\/a>Create new local repositories<\/h2>\n<p>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:<\/p>\n<ul>\n<li><a href=\"#create-local-empty\">Create an empty local repository<\/a><\/li>\n<li><a href=\"#create-local-solution-new\">Create a new solution under local Git version control<\/a><\/li>\n<li><a href=\"#create-local-solution-exists\">Put an existing solution under local Git version control<\/a><\/li>\n<\/ul>\n<h2><a name=\"create-local-empty\"><\/a>Create an empty local repository<\/h2>\n<p>You just want to create an empty local repository. In Visual Studio you can do this in a few seconds.<\/p>\n<p>Go to the Connect page and create the new repository.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/6523.GitConnectPublish01.png\" alt=\"\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Open the repository.&nbsp; This will set the repo as the active repo in Team Explorer.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/7853.GitConnectPublish02.png\" alt=\"\" \/><\/p>\n<p>Go ahead and commit the default <a href=\"http:\/\/git-scm.com\/book\/en\/Customizing-Git-Git-Attributes\">.gitattributes<\/a> and <a href=\"http:\/\/git-scm.com\/docs\/gitignore\">.gitignore<\/a> files that Visual Studio created for you. (We&#8217;ll talk more about these and other Git settings in a future post).<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/5756.GitConnectPublishChangesLink.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/3326.GitConnectPublish04.png\" alt=\"\" \/><\/p>\n<p>Your new local Git repository is now ready for you to use.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/4111.GitConnectPublish06.png\" alt=\"\" \/><\/p>\n<p>When you are ready, you can <a href=\"#publish\">publish<\/a> and share it with your team.<\/p>\n<h2><a name=\"create-local-solution-new\"><\/a>Create a new solution under local Git version control<\/h2>\n<p>Whenever you create a new code project, you can put it under local Git version control.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/3323.GitConnectPublish07.png\" alt=\"\" \/><\/p>\n<p>We cover this angle from start to finish in our <a href=\"http:\/\/tfs.visualstudio.com\/en-us\/learn\/code\/create-code-project-vs-git\/\">Welcome Portal tutorial<\/a>.<\/p>\n<h2><a name=\"create-local-solution-exists\"><\/a>Put an existing solution under local Git version control<\/h2>\n<p>If you&#8217;ve already got a solution in which you&#8217;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?<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/7446.GitConnectPublish08.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/1106.GitConnectPublish09.png\" alt=\"\" \/><\/p>\n<p>Now that your repository is created, go ahead and commit your files.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/8255.GitConnectPublish10.png\" alt=\"\" \/><\/p>\n<h2><a name=\"add\"><\/a>Add an existing local repository<\/h2>\n<p>Maybe you&#8217;ve got other repositories you&#8217;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.&nbsp; 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.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/4520.GitConnectPublish12.png\" alt=\"\" \/><\/p>\n<p>After you add the repository, you can open it and get to work in Visual Studio.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/4101.GitConnectPublish13.png\" alt=\"\" \/><\/p>\n<p>BTW, notice that nifty &#8220;Open in Command Prompt&#8221; command? Eventually you will likely need it to perform some tasks. If you don&#8217;t already have command-line tools installed, you can install some:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/5037.GitConnectPublish14.png\" alt=\"\" \/><\/p>\n<p>We&#8217;ll talk more about common scenarios for using these tools in a future post.<\/p>\n<h2><a name=\"clone\"><\/a>Clone a remote Git repository to your dev machine<\/h2>\n<p>Doesn&#8217;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.<\/p>\n<h2><a name=\"clone-tfs\"><\/a>Clone a TFS Git repository to your dev machine<\/h2>\n<p>Whether you are new to a team project or just setting up a new dev machine, to get working in a Git team project, <a href=\"http:\/\/tfs.visualstudio.com\/en-us\/learn\/code\/clone-vs-git\/\">clone it to your dev machine<\/a>.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/3884.VSGitClone07.png\" alt=\"\" \/><\/p>\n<h2><a name=\"clone-3rd-party\"><\/a>Clone a third-party Git repository to your dev machine<\/h2>\n<p>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.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/5824.GitConnectPublish15.png\" alt=\"\" \/><\/p>\n<h2><a name=\"publish\"><\/a>Publish your local repository<\/h2>\n<p>When you are ready to begin sharing some code on your dev machine with others, you publish the branch to the remote repository.<\/p>\n<h2><a name=\"publish-tfs\"><\/a>Publish to TFS<\/h2>\n<p>You can <a href=\"http:\/\/tfs.visualstudio.com\/en-us\/learn\/code\/publish-new-team-project-vs-git\/\">publish your code into Team Foundation Service<\/a>.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/5141.VSGitCodeUpload09.png\" alt=\"\" \/><\/p>\n<h2><a name=\"publish-3rd-party\"><\/a>Publish to a third-party service<\/h2>\n<p>You can publish your branch to a remote repository hosted on a third-party service such as CodePlex, GitHub, or Bitbucket.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/1680.GitConnectPublish19.png\" alt=\"\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-bottom: 0\"><a class=\"expander\" style=\"padding: 5px;background-color: #dddddd;font-weight: bold\" href=\"#\">Did you get the &#8220;Branch master does not exist&#8221; error? Click here.<\/a><\/p>\n<div id=\"PublishNoCommitsError\" class=\"expandable\" style=\"padding: 15px;margin-left: 25px;background-color: #dddddd;margin-top: 0\">\n<p><img decoding=\"async\" style=\"float: left;margin-right: 5px\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/1643.GitConnectPublish20.png\" alt=\"\" \/>This error occurs when you try to publish a local repository that does not yet have any commits. Getting past this point is no big deal. Just go commit at least one change and then publish the branch.<\/p>\n<p><img decoding=\"async\" style=\"margin-left: auto;margin-right: auto\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/3157.GitConnectPublish21.png\" alt=\"\" \/><img decoding=\"async\" style=\"margin-left: auto;margin-right: auto\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/1513.GitConnectPublish26.png\" alt=\"\" \/><\/div>\n<h2>After you publish<\/h2>\n<p>Having published your branch, Visual Studio has done two things for you:<\/p>\n<ul>\n<li>Set the remote of the local repository<\/li>\n<li>Pushed your active branch (in most cases this is &#8220;master&#8221;) to the remote repository<\/li>\n<\/ul>\n<p>After this is done, to collaborate with your team, you can as needed <a href=\"http:\/\/tfs.visualstudio.com\/en-us\/learn\/code\/pull-vs-git\/\">pull their changes<\/a> and <a href=\"http:\/\/tfs.visualstudio.com\/en-us\/learn\/code\/push-vs-git\/\">push your changes<\/a> to the remote repository.<\/p>\n<h2><a name=\"connect\"><\/a>Manage your connections<\/h2>\n<p>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.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/5140.GitConnectPublish27.png\" alt=\"\" \/><\/p>\n<p>Just right-click the repository you want to work and then choose Open or another command.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/02\/8838.GitConnectPublish28.png\" alt=\"\" \/><\/p>\n<h2><a name=\"feedback\"><\/a>Tell us what you think<\/h2>\n<p>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!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ &lt;!&#8211; Create, Connect, and Publish using Visual Studio with Git &#8211;&gt; By: Andy Lewis and Matthew Mitrik (MS) In the few days since we announced Visual Studio and Team Foundation Service support for Git, it&#8217;s been exciting to see so much interest, along with a lot of great feedback and questions. We will take [&hellip;]<\/p>\n","protected":false},"author":73,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[253,1,225],"tags":[],"class_list":["post-9718","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure-devops-server","category-devops","category-git"],"acf":[],"blog_post_summary":"<p>\/\/ &lt;!&#8211; Create, Connect, and Publish using Visual Studio with Git &#8211;&gt; By: Andy Lewis and Matthew Mitrik (MS) In the few days since we announced Visual Studio and Team Foundation Service support for Git, it&#8217;s been exciting to see so much interest, along with a lot of great feedback and questions. We will take [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/9718","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/73"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=9718"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/9718\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=9718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=9718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=9718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}