如何将未同步提交推给GitHub?

时间:2021-11-28 15:31:10

I have a GitHub source control tool added to my copy of Visual Studio 2013 and when I right click on the solution and make a commit it says created the commit locally. When I try to sync the commit with the server, the sync button is greyed out.

我在Visual Studio 2013的副本中添加了一个GitHub源代码控制工具,当我右键单击解决方案并提交时,它说在本地创建提交。当我尝试将提交与服务器同步时,同步按钮就会变成灰色。

My question is how do I set it up or what steps do I take so that the commit is pushed to the server?

我的问题是如何设置它,或者采取什么步骤将提交推到服务器?

如何将未同步提交推给GitHub?

4 个解决方案

#1


43  

It looks like you do not have the upstream remote / branch configured for this branch. Visual Studio operates as if the "push.default" configuration is set to "upstream".

看起来您没有为这个分支配置上游远程/分支。Visual Studio的操作方式就好像“push.default”配置设置为“上游”。

If you go to the branches page, this branch should be listed under the "Unpublished" branches section. From that page, you can choose to "publish" this branch by right clicking on the unpublished branch and selecting publish in the resulting context menu. This will push the branch to the origin remote (with a branch of the same name as your local branch) and set the upstream tracking information for this branch. From then on, you can push and fetch from the Unsynced Commits page.

如果您到分支页面,该分支应该在“未发布”分支部分中列出。在该页面中,您可以通过右键单击未发布的分支并在结果上下文菜单中选择publish来选择“发布”这个分支。这将将分支推到起源远程(具有与本地分支同名的分支),并为该分支设置上游跟踪信息。从那时起,您就可以从未同步的提交页面进行推送和获取。

Here is a screen capture of where you need to go to publish an unpublished branch:

这是一个屏幕截图,你需要去哪里发布一个未发布的分支:

如何将未同步提交推给GitHub?

#2


4  

You need to add the online GitHub repo as a remote in your local git repo.

您需要将在线GitHub repo添加到本地git repo中的远程。

On the command line, that's git remote add origin <urL>; I don't know if the VS git UI exposes this.

在命令行中,这是git远程添加源 ;我不知道VS git UI是否公开了这个。

#3


2  

We use Atlassian Stash but also found the Visual Studio UI a bit confusing at first. The sequence that works for us, using only the UI, is as follows:

我们使用了Atlassian hidden,但一开始也发现Visual Studio UI有点混乱。只使用UI的序列如下:

  1. First you have to add your "username" and e-mail address in the Git global settings via Team Explorer > Home > Git > Git Settings
  2. 首先,您必须在Git全局设置中添加您的“用户名”和电子邮件地址,通过Team Explorer > Home > Git > Git设置。
  3. On the "Solution Explorer" tab, right click on the solution and "Add Solution to Source Control" and choose Git.
  4. 在“解决方案资源管理器”选项卡上,右键单击解决方案,并“向源代码控制添加解决方案”并选择Git。
  5. On the "Team Explorer" tab, click on the repo you just created and go to branches
  6. 在“Team Explorer”选项卡上,单击刚刚创建的repo,转到分支
  7. Choose the master branch, right click on it and choose "Publish" - you will be asked for the remote URL whereupon after you enter it, you will get a username/password prompt (for the remote server i.e. GitHub, Stash, etc.)
    • All this is doing is git push origin masterbut Microsoft chose to make it confusing by giving it another name.
    • 这一切都是git push origin masterbut Microsoft选择了另一个名字来混淆。
  8. 选择主分支,右键单击它并选择“发布”,你将被要求远程URL于是你进去后,你会得到一个用户名/密码提示(远程服务器即GitHub、储备等)这些都是做的是git push起源masterbut微软选择混乱给它另一个名字。
  9. Wait for the "publish" to be completed (there will be a file transfer status shown in the UI)
  10. 等待“发布”完成(UI中显示文件传输状态)
  11. Once it is completed, go to the commits tab and you will see that all the options for Push/Pull/Fetch etc are available
  12. 完成之后,转到提交选项卡,您将看到Push/Pull/Fetch等等的所有选项都可用

Note: If you create another branch locally, you will have to push, er "publish", that one as well before the remote knows about it.

注意:如果您在本地创建另一个分支,那么您将不得不在远程知道它之前,将该分支“发布”。

Final note: Visual Studio will not create projects and repos for you on the remote. You have to make sure the repo is setup on the remote before you can push a branch to it.

最后注意:Visual Studio不会在远程上为您创建项目和repos。在将分支推到远程服务器之前,您必须确保在远程服务器上安装了repo。

Weird issue: We found that if you try to push to a branch but fail (due to incorrect URL or a permissions issue) that we had to go back to the command prompt to "fix" the remote configuration for the repo/branch. This is using the standard git command:

奇怪的问题:我们发现,如果您试图推到一个分支,但是失败了(由于错误的URL或权限问题),我们必须返回命令提示符以“修复”repo/branch的远程配置。这使用的是标准的git命令:

git remote add origin https://myuser@stash.mycompany.com/scm/myproject/myrepo.git

git远程添加来源https://myuser@stash.mycompany.com/scm/myproject/myrepo.git。

#4


0  

After you publish a branch as in @jamill's answer you may run into this.

在@jamill的回复中发布分支之后,您可能会遇到这种情况。

In Team Explorer, I was able to publish a branch, but then I could not do anything. Pull and Push were grayed out as shown:

在Team Explorer中,我可以发布一个分支,但是我什么都做不了。拉和推的灰色显示如下:

如何将未同步提交推给GitHub?

So I did Actions > Open Command Prompt. Then Type:

所以我做了动作>打开命令提示符。然后输入:

git push origin My_Branch_Name

After doing this I could see the branch and my commit in my remote. (Github or whatever in your case). Also when running the command, the output said,

这样做之后,我可以看到分支和我的提交在我的远程。(在你的例子中是Github)。同样,在运行命令时,输出说,

remote: Create pull request for My_Branch_Name: 

If you want to keep this branch and merge it into master, then you can create a pull request on your remote. Otherwise as in my case I want to abandon the branch. You don't have to do anything.

如果您想保留这个分支并将它合并到master中,那么您可以在远程上创建一个pull请求。否则,就像我的情况一样,我想放弃分支。你什么都不用做。

#1


43  

It looks like you do not have the upstream remote / branch configured for this branch. Visual Studio operates as if the "push.default" configuration is set to "upstream".

看起来您没有为这个分支配置上游远程/分支。Visual Studio的操作方式就好像“push.default”配置设置为“上游”。

If you go to the branches page, this branch should be listed under the "Unpublished" branches section. From that page, you can choose to "publish" this branch by right clicking on the unpublished branch and selecting publish in the resulting context menu. This will push the branch to the origin remote (with a branch of the same name as your local branch) and set the upstream tracking information for this branch. From then on, you can push and fetch from the Unsynced Commits page.

如果您到分支页面,该分支应该在“未发布”分支部分中列出。在该页面中,您可以通过右键单击未发布的分支并在结果上下文菜单中选择publish来选择“发布”这个分支。这将将分支推到起源远程(具有与本地分支同名的分支),并为该分支设置上游跟踪信息。从那时起,您就可以从未同步的提交页面进行推送和获取。

Here is a screen capture of where you need to go to publish an unpublished branch:

这是一个屏幕截图,你需要去哪里发布一个未发布的分支:

如何将未同步提交推给GitHub?

#2


4  

You need to add the online GitHub repo as a remote in your local git repo.

您需要将在线GitHub repo添加到本地git repo中的远程。

On the command line, that's git remote add origin <urL>; I don't know if the VS git UI exposes this.

在命令行中,这是git远程添加源 ;我不知道VS git UI是否公开了这个。

#3


2  

We use Atlassian Stash but also found the Visual Studio UI a bit confusing at first. The sequence that works for us, using only the UI, is as follows:

我们使用了Atlassian hidden,但一开始也发现Visual Studio UI有点混乱。只使用UI的序列如下:

  1. First you have to add your "username" and e-mail address in the Git global settings via Team Explorer > Home > Git > Git Settings
  2. 首先,您必须在Git全局设置中添加您的“用户名”和电子邮件地址,通过Team Explorer > Home > Git > Git设置。
  3. On the "Solution Explorer" tab, right click on the solution and "Add Solution to Source Control" and choose Git.
  4. 在“解决方案资源管理器”选项卡上,右键单击解决方案,并“向源代码控制添加解决方案”并选择Git。
  5. On the "Team Explorer" tab, click on the repo you just created and go to branches
  6. 在“Team Explorer”选项卡上,单击刚刚创建的repo,转到分支
  7. Choose the master branch, right click on it and choose "Publish" - you will be asked for the remote URL whereupon after you enter it, you will get a username/password prompt (for the remote server i.e. GitHub, Stash, etc.)
    • All this is doing is git push origin masterbut Microsoft chose to make it confusing by giving it another name.
    • 这一切都是git push origin masterbut Microsoft选择了另一个名字来混淆。
  8. 选择主分支,右键单击它并选择“发布”,你将被要求远程URL于是你进去后,你会得到一个用户名/密码提示(远程服务器即GitHub、储备等)这些都是做的是git push起源masterbut微软选择混乱给它另一个名字。
  9. Wait for the "publish" to be completed (there will be a file transfer status shown in the UI)
  10. 等待“发布”完成(UI中显示文件传输状态)
  11. Once it is completed, go to the commits tab and you will see that all the options for Push/Pull/Fetch etc are available
  12. 完成之后,转到提交选项卡,您将看到Push/Pull/Fetch等等的所有选项都可用

Note: If you create another branch locally, you will have to push, er "publish", that one as well before the remote knows about it.

注意:如果您在本地创建另一个分支,那么您将不得不在远程知道它之前,将该分支“发布”。

Final note: Visual Studio will not create projects and repos for you on the remote. You have to make sure the repo is setup on the remote before you can push a branch to it.

最后注意:Visual Studio不会在远程上为您创建项目和repos。在将分支推到远程服务器之前,您必须确保在远程服务器上安装了repo。

Weird issue: We found that if you try to push to a branch but fail (due to incorrect URL or a permissions issue) that we had to go back to the command prompt to "fix" the remote configuration for the repo/branch. This is using the standard git command:

奇怪的问题:我们发现,如果您试图推到一个分支,但是失败了(由于错误的URL或权限问题),我们必须返回命令提示符以“修复”repo/branch的远程配置。这使用的是标准的git命令:

git remote add origin https://myuser@stash.mycompany.com/scm/myproject/myrepo.git

git远程添加来源https://myuser@stash.mycompany.com/scm/myproject/myrepo.git。

#4


0  

After you publish a branch as in @jamill's answer you may run into this.

在@jamill的回复中发布分支之后,您可能会遇到这种情况。

In Team Explorer, I was able to publish a branch, but then I could not do anything. Pull and Push were grayed out as shown:

在Team Explorer中,我可以发布一个分支,但是我什么都做不了。拉和推的灰色显示如下:

如何将未同步提交推给GitHub?

So I did Actions > Open Command Prompt. Then Type:

所以我做了动作>打开命令提示符。然后输入:

git push origin My_Branch_Name

After doing this I could see the branch and my commit in my remote. (Github or whatever in your case). Also when running the command, the output said,

这样做之后,我可以看到分支和我的提交在我的远程。(在你的例子中是Github)。同样,在运行命令时,输出说,

remote: Create pull request for My_Branch_Name: 

If you want to keep this branch and merge it into master, then you can create a pull request on your remote. Otherwise as in my case I want to abandon the branch. You don't have to do anything.

如果您想保留这个分支并将它合并到master中,那么您可以在远程上创建一个pull请求。否则,就像我的情况一样,我想放弃分支。你什么都不用做。