如何使用 Git Bash 推送到 GitHub?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23315583/
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
How to push to GitHub using Git Bash?
提问by Ryan
Whenever I need to push my new local commits to GitHub I use the Windows GitHub desktop application. I open it up and click the sync button. I want to be able to do it from the Git Bash command line. I think the command I want to use is:
每当我需要将新的本地提交推送到 GitHub 时,我都会使用 Windows GitHub 桌面应用程序。我打开它并单击同步按钮。我希望能够从 Git Bash 命令行执行此操作。我想我要使用的命令是:
git push origin master
git push origin master
but when I do that I get some sort of invalid username error. I tried this:
但是当我这样做时,我会收到某种无效的用户名错误。我试过这个:
https://stackoverflow.com/a/20871910/280319
https://stackoverflow.com/a/20871910/280319
but when I do that and git push origin master
I get another error saying [email protected]:user/repo.git
is an invalid repo.
但是当我这样做时,git push origin master
我收到另一个错误消息,说[email protected]:user/repo.git
是一个无效的回购。
Now I'm at the point where I changed my origin back to https://github.com/user/repo.git
(I think that's what it was set to before). But since I did that my local repo is now not "pointing" to the correct remote(I can tell because git status
doesn't list 1 out of sync commit and neither does the GitHub desktop app).
现在我将我的原点改回https://github.com/user/repo.git
(我认为这就是它之前的设置)。但是因为我这样做了,所以我的本地存储库现在没有“指向”正确的远程(我可以判断,因为git status
没有列出 1 个不同步的提交,GitHub 桌面应用程序也没有)。
This is all just on a test repo of mine.
这一切都只是在我的测试仓库中。
So what do I have to do so that I can push to GitHub using the Git Bash command line?
那么我必须做什么才能使用 Git Bash 命令行推送到 GitHub?
回答by Steven Penny
Usually what I do in this situation is just "start over". It is probably not the optimal way to do this, but it works.
通常我在这种情况下所做的只是“重新开始”。这可能不是执行此操作的最佳方法,但它确实有效。
Back up your commits, for example to back up the last 4 commits that have not been pushed
git format-patch -4
Re clone the repo
git clone https://github.com/svnpenn/a
Apply your commits. Note since you said Windows, you might need to add
--keep-cr
heregit am ../0001-type-magick-dev-null-exit.patch
try
push
ing again
备份您的提交,例如备份未推送的最后 4 个提交
git format-patch -4
重新克隆 repo
git clone https://github.com/svnpenn/a
应用您的提交。请注意,既然您说的是 Windows,您可能需要在
--keep-cr
此处添加git am ../0001-type-magick-dev-null-exit.patch
再试
push
一次