Git/GitHub can't push to master
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.
Here's what I did (and this worked) -
git remote add origin git://github.com/my_user_name/my_repo.git
Now when I try to push the repository 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 [email protected]:my_user_name/my_repo.git
Solution 1:
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 [email protected]: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 [email protected]: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.
Solution 2:
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
.
Solution 3:
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 = [email protected]:my_user_name/my_repo.git
(And conversely, the git remote set-url...
invocation produces the above change.)