Git/GitHub can't push to master

前端 未结 11 1807
抹茶落季
抹茶落季 2020-12-07 07:09

I am new to Git/GitHub and ran into an issue. I created a test project and added it to the local repository. Now I am trying to add files/project to the remote repository.

相关标签:
11条回答
  • 2020-12-07 07:49

    Use Mark Longair's answer, but make sure to use the HTTPS link to the repository:

    git remote set-url origin https://github.com/my_user_name/my_repo.git
    

    You can use then git push origin master.

    0 讨论(0)
  • 2020-12-07 07:52

    The fastest way yuo get over it is to replace origin with the suggestion it gives.

    Instead of git push origin master, use:

    git push git@github.com:my_user_name/my_repo.git master
    
    0 讨论(0)
  • 2020-12-07 07:56

    This error occurs when you clone a repo using a call like:

    git clone git://github.com/....git
    

    This essentially sets you up as a pull-only user, who can't push up changes.

    I fixed this by opening my repo's .git/config file and changing the line:

    [remote "origin"]
        url = git://github.com/myusername/myrepo.git
    

    to:

    [remote "origin"]
        url = ssh+git://git@github.com/myusername/myrepo.git
    

    This ssh+git protocol with the git user is the authentication mechanism preferred by Github.

    The other answers mentioned here technically work, but they all seem to bypass ssh, requiring you to manually enter a password, which you probably don't want.

    0 讨论(0)
  • 2020-12-07 07:57

    GitHub doesn't support pushing over the Git protocol, which is indicated by your use of the URL beginning git://. As the error message says, if you want to push, you should use either the SSH URL git@github.com:my_user_name/my_repo.git or the "smart HTTP" protocol by using the https:// URL that GitHub shows you for your repository.

    (Update: to my surprise, some people apparently thought that by this I was suggesting that "https" means "smart HTTP", which I wasn't. Git used to have a "dumb HTTP" protocol which didn't allow pushing before the "smart HTTP" that GitHub uses was introduced - either could be used over either http or https. The differences between the transfer protocols used by Git are explained in the link below.)

    If you want to change the URL of origin, you can just do:

    git remote set-url origin git@github.com:my_user_name/my_repo.git
    

    or

    git remote set-url origin https://github.com/my_user_name/my_repo.git
    

    More information is available in 10.6 Git Internals - Transfer Protocols.

    0 讨论(0)
  • 2020-12-07 07:57

    The below cmnds will fix the issue.

     git pull --rebase
     git push
    
    0 讨论(0)
  • 2020-12-07 07:59

    I added my pubkey to github.com and this was successful:

    ssh -T git@github.com
    

    But I received the "You can't push" error after having wrongly done this:

    git clone git://github.com/mygithubacct/dotfiles.git
    git remote add origin git@github.com:mygithubacct/dotfiles.git
    ...edit/add/commit
    git push origin master
    

    Instead of doing what I should have done:

    mkdir dotfiles
    cd dotfiles
    git init
    git remote add origin git@github.com:mygithubacct/dotfiles.git
    git pull origin master
    ...edit/add/commit
    git push origin master
    
    0 讨论(0)
提交回复
热议问题