How to push to GitHub using Git Bash?

送分小仙女□ 提交于 2019-12-06 09:00:54

问题


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:

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

but when I do that and git push origin masterI get another error saying git@github.com:user/repo.git is an invalid repo.

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).

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?


回答1:


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-cr here

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



来源:https://stackoverflow.com/questions/23315583/how-to-push-to-github-using-git-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!