如何使用 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:59:59  来源:igfitidea点击:

How to push to GitHub using Git Bash?

gitgithubgit-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 masterI get another error saying [email protected]:user/repo.gitis 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 statusdoesn'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.

通常我在这种情况下所做的只是“重新开始”。这可能不是执行此操作的最佳方法,但它确实有效。

  1. Back up your commits, for example to back up the last 4 commits that have not been pushed

    git format-patch -4
    
  2. Re clone the repo

    git clone https://github.com/svnpenn/a
    
  3. Apply your commits. Note since you said Windows, you might need to add --keep-crhere

    git am ../0001-type-magick-dev-null-exit.patch
    
  4. try pushing again

  1. 备份您的提交,例如备份未推送的最后 4 个提交

    git format-patch -4
    
  2. 重新克隆 repo

    git clone https://github.com/svnpenn/a
    
  3. 应用您的提交。请注意,既然您说的是 Windows,您可能需要在--keep-cr此处添加

    git am ../0001-type-magick-dev-null-exit.patch
    
  4. 再试push一次