Git/GitHub can't push to master

前端 未结 11 1808
抹茶落季
抹茶落季 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 08:09

    I had this issue after upgrading the Git client, and suddenly my repository could not push.

    I found that some old remote had the wrong value of url, even through my currently active remote had the same value for url and was working fine.

    But there was also the pushurl param, so adding it for the old remote worked for me:

    Before:

    [remote "origin"]
        url = git://github.com/user/repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
        pushurl = git@github.com:user/repo.git
    

    NOTE: This part of file "config" was unused for ages, but the new client complained about the wrong URL:

    [remote "composer"]
        url = git://github.com/user/repo.git
        fetch = +refs/heads/*:refs/remotes/composer/*
    

    So I added the pushurl param to the old remote:

    [remote "composer"]
        url = git://github.com/user/repo.git
        fetch = +refs/heads/*:refs/remotes/composer/*
        pushurl = git@github.com:user/repo.git
    
    0 讨论(0)
  • 2020-12-07 08:12

    There is a simple solution to this for someone new to this:

    Edit the configuration file in your local .git directory (config). Change git: to https: below.

    [remote "origin"]
        url = https://github.com/your_username/your_repo
    
    0 讨论(0)
  • 2020-12-07 08:12

    If you go to http://github.com/my_user_name/my_repo you will see a textbox where you can select the git path to your repository. You'll want to use this!

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

    To set https globally instead of git://:

    git config --global url.https://github.com/.insteadOf git://github.com/
    
    0 讨论(0)
  • 2020-12-07 08:14

    Mark Longair's solution using git remote set-url... is quite clear. You can also get the same behavior by directly editing this section of the .git/config file:

    before:

    [remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git://github.com/my_user_name/my_repo.git
    

    after:

    [remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@github.com:my_user_name/my_repo.git
    

    (And conversely, the git remote set-url... invocation produces the above change.)

    0 讨论(0)
提交回复
热议问题