Git/github can't push to master

采用git clone方法构建本地库后,提交(git push)的时候出现错误:

$ git push
fatal: remote error: 
  You can't push to git://github.com/User/Proj.git
  Use git@github.com:User/Proj.git
 
这时候,需要设置提交的路径来解决

$ git remote set-url origin git@github.com:User/Proj.git

或者每次提交的时候采用另一种方式:

$ git push git@github.com:User/Proj.git

或者更改.git中config的url = git@github.com:User/Proj.git




git remote add origin git://github.com/my_user_name/my_repo.git

Now when I try to push the repo to github, using the following command, I get the following error -

git push origin master

Error -

fatal: remote error: 
You can't push to git://github.com/my_user_name/my_repo.git
Use git@github.com:my_user_name/my_repo.git


solution

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.

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


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

posted on 2013-01-24 10:52  Richard.FreeBSD  阅读(427)  评论(0编辑  收藏  举报

导航