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?
Publish will push the branch to the remote AND set up the local branch to track the remote branch. Push just pushes and doesn't set upstream tracking information (ie: branch. <name>. remote and branch.
To push a local branch to the remote, right click on that branch in Team Explorer. From the context menu, that pops up on the screen, select Push Branch.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With