214

I have looked through many web pages on the new Git integration in VS 2013 and they do not deal with adding an existing solution to Github. In fact I can't find much on using GitHub instead of Visual Studio Online.

Can anyone tell me how I start from an existing solution and add it to Github using the tools in VS 2013.

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Richard210363
  • 8,342
  • 6
  • 37
  • 63
  • Why not just do it from command line? It should only be about 5 commands *(create repo, add project to repo [2 commands], add remote, push to remote)*? All of the commands are pretty well documented. – Roman Nov 15 '13 at 15:12
  • 3
    Adding it through github for VS will add "Open with Visual Studio" button on the github page. minor but useful :) – Ateik Feb 02 '16 at 13:27

9 Answers9

354

OK this worked for me.

  1. Open the solution in Visual Studio 2013
  2. Select File | Add to Source Control
  3. Select the Microsoft Git Provider

That creates a local GIT repository

  1. Surf to GitHub
  2. Create a new repository DO NOT SELECT Initialize this repository with a README

That creates an empty repository with no Master branch

  1. Once created open the repository and copy the URL (it's on the right of the screen in the current version)
  2. Go back to Visual Studio
    • Make sure you have the Microsoft Git Provider selected under Tools/Options/Source Control/Plug-in Selection
  3. Open Team Explorer
  4. Select Home | Unsynced Commits
  5. Enter the GitHub URL into the yellow box (use HTTPS URL, not the default shown SSH one)
  6. Click Publish
  7. Select Home | Changes
  8. Add a Commit comment
  9. Select Commit and Push from the drop down

Your solution is now in GitHub

codemann8
  • 372
  • 7
  • 29
Richard210363
  • 8,342
  • 6
  • 37
  • 63
  • 5
    I want to add that currently ssh is not supported, so you have to use the https protocol. If already the wrong url is used, you can use _git remote set-url origin https://..._ to change it. – Michael Dietrich Mar 30 '14 at 19:25
  • 2
    Thanks, this helped me. Checking initialize in github was ruining it for me. – josha76 May 04 '14 at 02:21
  • 7
    If you happen to have jumped the gun and created the repo with the readme, you can recover by opening a git shell (bash or ps) and from the root directory type git remote rm origin. That will bring back the URL text box in VS2013 and allow you to re-add the remote server. There may be a way to do it in VS but I couldn't find it. – bob May 08 '14 at 19:55
  • 5
    When I click Publish it tells me: `You must commit changes to your local repository before you can publish.` What do I do? How do I commit changes to my local repository? – Mark Kramer Jul 16 '14 at 11:11
  • 5
    You click on Home | Changes. Then enter a commit message in the yellow box and click Commit. – Richard210363 Aug 11 '14 at 10:34
  • Hm, after "Add to Source Control" i just get "Open SourceSafe Database" but I don't want to use SourceSafe anymore.. Have upgraded to 2013 and want to use git. – runholen Aug 12 '14 at 09:07
  • I believe that means the project is associated with a SourceSafe repository. I would think you would need to unbind source control from the project (File | Source Control | Change Source Control) and then start again. I don't use SourceSafe so I cannot say for certain. – Richard210363 Aug 12 '14 at 11:37
  • 1
    I had to go to Tools/Options/Source Control/Plug-in Selection and select the "Microsoft Git Provider" from the drop-down first. – Mike Wise Feb 24 '15 at 10:51
  • Make sure you have your solution highlighted or you won't see File | Add to Source Control. I had my project highlighted and could not figure out why that option was missing. – rsrobbins Apr 08 '16 at 18:50
  • Home | Unsynced Commits is now Home | Sync in 2015 – Nic Sep 14 '16 at 15:29
  • There is no yellow box in step 5. For me, it fails there. – Cool Blue Oct 18 '16 at 03:53
  • 1
    There's no longer an "Add to Source Control" under the File menu (in VS2015). Can you update this answer? – Nic Feb 09 '17 at 03:15
91

There is a lot easier way to do this that doesn't even require you to do anything outside Visual Studio.

  • Open your project in Visual Studio
  • File> Add to source control
  • Open Team Explorer, click on Home button, proceed to "Sync" and there you'd find the "Publish to GitHub". Click on "Get Started"
  • Type title of your repository and description (optionally).
  • Click on "Publish"

That's all. Visual Studio github plugin automatically created repository for you and configured everything. Now just click on Home and choose "Changes" tab and finally commit your first commit.

MaKiPL
  • 1,200
  • 8
  • 15
  • 20
    Don't get overwhelmed by the number of votes. This one works and is much simpler, at least in VS2015. – dotNET Sep 06 '16 at 15:24
  • 3
    I couldn't find the github thing So i had to use this : https://visualstudio.github.com/ – ʍѳђઽ૯ท Sep 21 '16 at 14:45
  • This is what I was looking for. My experience was slightly different however. When I hit `Add to source control`, I was brought directly to the screen to add the first commit to what appeared to be an automatically created local git repository, which was exactly what I wanted. VS2015 Community. – parker.sikand Oct 08 '16 at 17:57
  • The question clearly states Visual Studio _2013_, not 2015 – Cool Blue Oct 18 '16 at 03:55
  • 3
    I'm pretty sure this solution assumes the Github extension for VS2015 is installed. You can get it here like an above comment described: visualstudio.github.com – Greg Mar 07 '17 at 19:24
  • 2
    Just used this method to push a VS2017 solution to a local Gogs repository. – Peter M Mar 31 '17 at 18:42
  • @Greg, is that the same thing that we get from "Tools" | "Extensions and Updates..." in VS? – Sam Hobbs May 06 '17 at 23:05
  • This should be the approved answer, since it describe how to do so with current release of VS, assuming you have installed the github extension from Tools/Extensions and Updates – Max Favilli Jul 09 '17 at 00:14
  • This was the easiest, most straight-forward means. I already think hard enough and don't need to spend more time learning command line git commands. – Steve Oct 15 '17 at 04:03
  • where is Select File | Add to Source Control button located for visual studio 2017 – Prageeth godage Oct 04 '18 at 05:32
14

This question has already been answered accurately by Richard210363.

However, I would like to point out that there is another way to do this, and to warn that this alternate approach should be avoided, as it causes problems.

As R0MANARMY stated in a comment to the original question, it is possible to create a repo from the existing solution folder using the git command line or even Git Gui. However, when you do this it adds all the files below that folder to the repo, including build output (bin/ obj/ folders) user options files (.suo, .csproj.user) and numerous other files that may be in your solution folder but that you don't want to include in your repo. One unwanted side effect of this is that after building locally, the build output will show up in your "changes" list.

When you add using "Select File | Add to Source Control" in Visual Studio, it intelligently includes the correct project and solution files, and leaves the other ones out. Also it automatically creates a .gitignore file that helps prevent these unwanted files from being added to the repo in the future.

If you have already created a repo that includes these unwanted files and then add the .gitignore file at a later time, the unwanted files will still remain part of the repo and will need to be removed manually... it's probably easier to delete the repo and start over again by creating the repo the correct way.

jjjjs
  • 1,500
  • 13
  • 9
  • I used the method proposed above by MaKiPL. It worked. and it did NOT have the shortcomings described by jjjjs. I found the method proposed by MaKiPL to be much easier than using a Git commands. – glenn garson Jul 27 '17 at 16:30
7
  • From the Team Explorer menu click "add" under the Git repository section (you'll need to add the solution directory to the Local Git Repository)
  • Open the solution from Team Explorer (right click on the added solution - open)
  • Click on the commit button and look for the link "push"

Visual Studio should now ask your GitHub credentials and then proceed to upload your solution.

Since I have my Windows account connected to Visual Studio to work with Team Foundation I don't know if it works without an account, Visual Studio will keep track of who commits so if you are not logged in it will probably ask you to first.

5

Well, I understand this question is Visual Studio GUI related, but maybe the asker can try this trick also. Just giving a different perspective in solving this problem.

I like to use terminal a lot for GIT, so here are the simple steps:

Pre-requisites...

  • If it's Linux or MAC, you should have git packages installed on your machine
  • If it's Windows, you can try to download git bash software

Now,

  1. Goto Github.com
  2. In your account, create a New Repository
  3. Don't create any file inside the repository. Keep it empty. Copy its URL. It should be something like https://github.com/Username/ProjectName.git

  4. Open up the terminal and redirect to your Visual Studio Project directory

  5. Configure your credentials

    git config --global user.name "your_git_username"
    git config --global user.email "your_git_email"
    
  6. Then type these commands

    git init
    git add .
    git commit -m "First Migration Commit"
    git remote add origin paste_your_URL_here
    git push -u origin master
    

Done...Hope this helps

Nish
  • 695
  • 1
  • 7
  • 14
  • on the last line, this git push -u origin master, it gave error saying remote contains work that you do not have locally (it was freshly created and was empty). Then when tried to pull again. "there is no tracking info of current branch" Git is a mystery – Blue Clouds Jul 13 '18 at 10:09
  • this [link](https://rubygarage.org/blog/most-basic-git-commands-with-examples) provides some explanation of the above mentioned commands – Tendai Mare Apr 21 '19 at 07:45
1

My problem is that when i use https for the remote URL, it doesn't work, so I use http instead. This allows me to publish/sync with GitHub from Team Explorer instantly.

Tarun
  • 2,808
  • 3
  • 22
  • 21
  • I wish I knew what "doesn't work" means so I had a better idea of whether this might be relevant to problems I have had. – Sam Hobbs Feb 15 '15 at 02:26
0

None of the answers were specific to my problem, so here's how I did it.

This is for Visual Studio 2015 and I had already made a repository on Github.com

If you already have your repository URL copy it and then in visual studio:

  • Go to Team Explorer
  • Click the "Sync" button
  • It should have 3 options listed with "get started" links.
  • I chose the "get started" link against "publish to remote repository", which it the bottom one
  • A yellow box will appear asking for the URL. Just paste the URL there and click publish.
Lee
  • 3,869
  • 12
  • 45
  • 65
0

It's a few less clicks in VS2017, and if the local repo is ahead of the Git clone, click Source control from the pop-up project menu:

enter image description here
This brings up the Team Explorer Changes dialog:

enter image description here
Type in a description- here it's "Stack Overflow Example Commit".
Make a choice of the three options on offer, all of which are explained here.

Laurie Stearn
  • 959
  • 1
  • 13
  • 34
0

Here is what worked for me using Visual Studio 2019

  1. Go to Team Explorer and click open and select your solution which you want to add to git. enter code here

  2. After doing this there will be option at bottom right which says Add To Source Control click it and you will get option to publish it to the repository you want like azure DevOps or git. enter image description here

  3. Finally Last Step

    enter image description here

Ninja
  • 338
  • 4
  • 12