24

I'm using VS.NET 2013 with the integrated Git tools, and attempting to publish my master branch to an existing repository I set up on GitHub. I'm using the VS.NET tools in the IDE exclusively and would like please any responses to follow using these tools if possible as opposed to a command line.

All of my changes have been committed locally and I just need to publish the branch to GitHub. However, when I try and publish my local master branch I receive the following error:

You cannot publish local branch master to the remote repository origin because a branch with the same name already exists there. You might want to rename your local branch and try again.

I know there is a lengthy article to this here, but I'm trying to remedy this from VS.NET or online at GutHub directly if possible. At best I want to better understand the issue.

I'm almost positive this issue was caused by me selecting the option Initialize this repository with a README selection on GitHub instead of creating a blank repositoy that my local changes could be pushed to. I think GutHub has used the same branch name already and it is causing a conflict.

I suppose I could delete the repository on GitHub and start from scratch, but was hoping to get this ironed out either from VS.NET or GitHub. Does anyone know how I can make it so my master branch can be successfully published?

Community
  • 1
  • 1
atconway
  • 20,624
  • 30
  • 159
  • 229

8 Answers8

37

Since I had just created the repository and there were no users, the solution was to delete the repository from Github (under 'Settings' menu) and create it again (once deleted I could use the same name). The trick is to not initialize the repository from GitHub - allow VS.NET to do this on 1st sync. Now it works wonderfully from VS.NET.

If I would not have deleted the repository, I would of had to use some external tools to either rename the local repository, or use sync from another tool (like TortoiseGit) that allows forcing to overwrite the branch on sync. It did not appear there was anything native to VS.NET that would allow this to occur.

atconway
  • 20,624
  • 30
  • 159
  • 229
  • 5
    I'm running into this same issue. It's ridiculous. I originally just used GitHub for Windows, so my local master is already tied to my GitHub repo's master. There's no good reason for VS to not simply honor that setup. – Major Productions Sep 26 '14 at 20:37
  • Thank you! Struggling with this for a bit now! – pceccon Jun 10 '15 at 21:19
17

There is a fix for this:

Go to your command prompt and change to your solution directory. From there you should be able to run git commands. You may have to install git if you haven't already Run 'git pull origin master'. This should merge your GitHub repo with your local repo. That's all we have to do from the command prompt. Now go back to Visual Studio

You may get some conflicts, if you do you will have to resolve these and commit locally again. Visual Studio will tell you if there are any conflicts. Once any conflicts are resolved, click on the 'master' link near the top of the pane. It should give you a dropdown with an item called 'manage branches'. Click it. You should see a branch called 'master' under the heading 'Unpublished Branches' Right click on master and click on 'Publish Branch' Now you can click on the 'unsynced changes' link again and you will see that the 'Sync' button is not greyed out anymore Click on Sync and you're done!

Source & credit: http://zanemayo.com/using_git_and_github_with_visual_studio.html

Oleg Fridman
  • 1,560
  • 16
  • 16
  • Just to review a comment from my OP: "I know there is a lengthy article to this here, but I'm trying to remedy this **from VS.NET or online at GutHub directly if possible**" Using the command line wasn't something I wanted to do at the time, but I realize it was possible to fix using it. – atconway Jan 19 '15 at 16:40
3

VS 2013 will initialize the GIT repository when your first commit with sync. So, simple solution is to delete the GIT repository and recreate it without initialize option.

enter image description here

marvelTracker
  • 4,691
  • 3
  • 37
  • 49
2

I experienced this problem in Visual Studio 2015 and this is how i got it fixed.

  1. Connect to your local git repository
  2. Open Branch
  3. Right Click On the master branch
  4. Select Open Command Prompt
  5. Run git pull origin master (This command will pull changes from the origin remote, master branch and merge them to the local checked-out branch.)
  6. Publish Your Repository .
Frank Odoom
  • 1,545
  • 18
  • 19
  • One note on this - the OP tag was for `Visual Studio 2013` which may have different and outdated Git tooling as compared to 2015 for the solution above. – atconway Sep 07 '16 at 04:33
1

I know this an old thread, but the following worked for me: Merge remote-tracking branch 'refs/remotes/origin/master'

In VS, go to Team Explorer > Branches; then tell VS to merge your remote branch onto master.

This appears to have worked for me. No need to delete anything, no need to use a console...we're VS devs, we don't like consoles...and no need for third party downloads (even if some of them are nice to have and easy to use.)

Mike_Matthews_II
  • 722
  • 6
  • 15
0

The solution for me was pretty simple:

Open Git Bash in the source directory.

execute:

git push origin -f

This solved the problem.

For some reason, my VS2013 does not actually create a git repository when you choose the create repository checkbox, so I have to create the repository manually.

This temporarily annoying problem is solved by

git init
git remote add origin https://(bitbucket username)@bitbucket.org/(bitbucket project name)/(bitbucket repository name).git
git add .
git push origin -f

I know this is contrary to the basic methodology of wanting to only use the Visual Studio interface, but there is a problem with VS2013 and this is the workaround for me.

Timothy Dooling
  • 470
  • 1
  • 4
  • 17
0

There is good solution:

Click the home button in team Explore,

enter image description here

Then Click on Branches below will be shown

enter image description here

Create a new Branch Named same as your local Project / Solution Name. Delete the main branch After that Click home button then click Sync and then Push. after that go to bitbucket or Git web Page and select the newly created branch your local code will already be pushed on GIT.

0

I am having the same issue as well. I followed the same steps on some of the answers here but none of it works on my Visual Studio 2015 Professional Edition. Here are the steps that solved my issue.

1.) First delete the git source control files in order to start again linking your solution to your Github repository.

enter image description here

2.) Delete your repository on Github account under settings. Then create a new empty repository and copy the new link.

enter image description here

3.) Re-open your solution in Visual Studio 2015, right click your solution and choose

Add Solution To Source Control.

enter image description here

4.) Beneath your Visual Studio IDE, look for unpublished commits and click it.

enter image description here

5.) Re-enter the new Github empty repository that you have copied on Step 2.

enter image description here

Willy David Jr
  • 8,604
  • 6
  • 46
  • 57