git 从 VS.NET 将 master 分支发布到 GitHub 时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25653830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error publishing master branch to GitHub from VS.NET
提问by atconway
I'm using VS.NET 2013 with the integrated Git tools, and attempting to publish my master
branch to an existingrepository 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 possibleas opposed to a command line.
我将 VS.NET 2013 与集成的 Git 工具一起使用,并尝试将我的master
分支发布到我在 GitHub 上设置的现有存储库。我在 IDE 中专门使用 VS.NET 工具,如果可能,而不是命令行,请使用这些工具做出任何回应。
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:
我的所有更改都已在本地提交,我只需要将分支发布到 GitHub。但是,当我尝试发布本地master
分支时,收到以下错误:
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.
您不能将本地分支 master 发布到远程存储库源,因为那里已经存在同名分支。您可能想要重命名本地分支并重试。
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.
我知道有一个长篇文章这一这里,但我想在GutHub直接如有可能解决这个问题,从VS.NET或在线。充其量我想更好地理解这个问题。
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.
我几乎肯定这个问题是由于我Initialize this repository with a README
在 GitHub 上选择了选项而不是创建一个可以将我的本地更改推送到的空白存储库引起的。我认为 GutHub 已经使用了相同的分支名称,这导致了冲突。
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?
我想我可以删除 GitHub 上的存储库并从头开始,但希望从 VS.NET 或 GitHub 解决这个问题。有谁知道我怎么做master
才能成功发布我的分支?
回答by atconway
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 notinitialize the repository from GitHub - allow VS.NET to do this on 1st sync. Now it works wonderfully from VS.NET.
由于我刚刚创建了存储库并且没有用户,因此解决方案是从 Github 中删除存储库(在“设置”菜单下)并重新创建(删除后我可以使用相同的名称)。诀窍是不要从 GitHub 初始化存储库 - 允许 VS.NET 在第一次同步时执行此操作。现在它在 VS.NET 中运行得非常好。
If I would nothave 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.
如果我不删除存储库,我将不得不使用一些外部工具来重命名本地存储库,或者使用另一个工具(如 TortoiseGit)的同步,允许强制覆盖同步分支。VS.NET 似乎没有任何本机允许这种情况发生。
回答by Darky711
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
转到您的命令提示符并更改到您的解决方案目录。从那里你应该能够运行 git 命令。如果您尚未运行“git pull origin master”,则可能需要安装 git。这应该将您的 GitHub 存储库与本地存储库合并。这就是我们在命令提示符下要做的全部事情。现在回到 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!
你可能会遇到一些冲突,如果你这样做了,你将不得不解决这些冲突并再次在本地提交。Visual Studio 会告诉您是否存在任何冲突。解决任何冲突后,单击窗格顶部附近的“主”链接。它应该为您提供一个名为“管理分支”的项目的下拉列表。点击它。您应该在“未发布的分支”标题下看到一个名为“master”的分支右键单击 master 并单击“发布分支”现在您可以再次单击“未同步的更改”链接,您将看到“同步”按钮是不再变灰点击同步,你就完成了!
Source & credit: http://zanemayo.com/using_git_and_github_with_visual_studio.html
来源和信用:http: //zanemayo.com/using_git_and_github_with_visual_studio.html
回答by marvelTracker
回答by Frank Odoom
I experienced this problem in Visual Studio 2015 and this is how i got it fixed.
我在 Visual Studio 2015 中遇到了这个问题,这就是我解决它的方法。
- Connect to your local git repository
- Open Branch
- Right Click On the master branch
- Select Open Command Prompt
- 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.) - Publish Your Repository .
- 连接到本地 git 存储库
- 开设分行
- 右键单击主分支
- 选择打开命令提示符
- 运行
git pull origin master
(此命令将从远程源、主分支拉取更改并将它们合并到本地检出分支。) - 发布您的存储库。
回答by Mike_Matthews_II
I know this an old thread, but the following worked for me: Merge remote-tracking branch 'refs/remotes/origin/master'
我知道这是一个旧线程,但以下对我有用:合并远程跟踪分支 'refs/remotes/origin/master'
In VS, go to Team Explorer > Branches; then tell VS to merge your remote branch onto master.
在 VS 中,转到 Team Explorer > Branches;然后告诉 VS 将您的远程分支合并到 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.)
这似乎对我有用。不需要删除任何东西,不需要使用控制台……我们是 VS 开发人员,我们不喜欢控制台……也不需要第三方下载(即使其中一些很好用且易于使用)用。)
回答by Timothy Dooling
The solution for me was pretty simple:
对我来说,解决方案非常简单:
Open Git Bash in the source directory.
在源目录中打开 Git Bash。
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.
出于某种原因,当您选择创建存储库复选框时,我的 VS2013 实际上并未创建 git 存储库,因此我必须手动创建存储库。
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.
我知道这与只想使用 Visual Studio 界面的基本方法背道而驰,但是 VS2013 存在问题,这就是我的解决方法。
回答by M Usman Shahid
There is good solution:
有一个很好的解决方案:
Click the home button in team Explore,
单击团队探索中的主页按钮,
Then Click on Branches below will be shown
然后点击下面的分支将显示
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.
创建一个与本地项目/解决方案名称相同的新分支。删除主分支之后单击主页按钮然后单击同步然后推送。之后,转到 bitbucket 或 Git 网页并选择新创建的分支,您的本地代码已经被推送到 GIT 上。
回答by Willy David Jr
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.
我也有同样的问题。我对这里的一些答案执行了相同的步骤,但没有一个适用于我的 Visual Studio 2015 专业版。以下是解决我的问题的步骤。
1.) First delete the git source control files in order to start again linking your solution to your Github repository.
1.) 首先删除 git 源控制文件,以便重新开始将您的解决方案链接到您的 Github 存储库。
2.) Delete your repository on Github account under settings. Then create a new empty repository and copy the new link.
2.) 在设置下删除您在 Github 帐户上的存储库。然后创建一个新的空存储库并复制新链接。
3.) Re-open your solution in Visual Studio 2015, right click your solution and choose
3.) 在 Visual Studio 2015 中重新打开您的解决方案,右键单击您的解决方案并选择
Add Solution To Source Control.
将解决方案添加到源代码管理。
4.) Beneath your Visual Studio IDE, look for unpublished commits and click it.
4.) 在您的 Visual Studio IDE 下,查找未发布的提交并单击它。
5.) Re-enter the new Github empty repository that you have copied on Step 2.
5.) 重新输入您在第 2 步中复制的新 Github 空存储库。