155

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 git@github.com:my_user_name/my_repo.git
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kapso
  • 11,703
  • 16
  • 58
  • 76
  • There's a help link (http://help.github.com/) at the bottom of all the github pages. The help describe many topics including this one. I'd suggest reading those and then asking questions about specific things you don't understand. – jamessan Sep 25 '11 at 21:23
  • 21
    if jamessan had pointed to a specific location in the help pages, that would have been more useful. – Deonomo Jul 10 '12 at 19:19
  • 1
    possible duplicate of [git github cannot push to origin](http://stackoverflow.com/questions/11101203/git-github-cannot-push-to-origin) – gion_13 Sep 05 '13 at 10:54
  • If you are reading this Mar 17th 2022, check down detector. Github is failing. – Peter Cotton Mar 17 '22 at 14:26

11 Answers11

249

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.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • So i changed the URL and retried the push, get this error now - ERROR: my_user_name/my_repo.git doesn't exist. Did you enter it correctly? fatal: The remote end hung up unexpectedly – kapso Sep 25 '11 at 21:30
  • Is the URL you've set definitely the one that you can copy-and-paste from the page for your repository on GitHub? (It's case sensitive, incidentally.) – Mark Longair Sep 25 '11 at 21:39
  • well the repo has not been created yet on github, so when I try http://github.com/my_user_name/my_repo ...not sure if thats what you meant – kapso Sep 25 '11 at 22:07
  • 1
    OK, well you have to create the repository on GitHub before you can push to it - when you do so, it'll give you instructions on how to clone or push to the repository. – Mark Longair Sep 25 '11 at 22:10
  • 1
    I just had this very same problem. Actually the problem was that you have slash "/" right in between github.com and your username. And it should be a colon ":". That is the problem :D – Wilmer E. Henao Jun 21 '13 at 07:39
  • 2
    @WilmerEHenaoH: that might have been *your* problem, but it wasn't the problem in the question or with in my answer ;) (Just for interest, there is sometimes confusion over [the two styles of SSH URL in git](http://stackoverflow.com/a/5281822/223092), one of which uses a colon to separate hostname and path and the other of which doesn't.) – Mark Longair Jun 22 '13 at 07:59
  • Cool. I am also a newbie to Github. My very first exploration of github was successful. When I tried doing it for a second time for a different project, I ended up in the same error saying "github error: .git doesn't exist. Did you enter it correctly?". After reading through Mark Longair's suggestion, I created a new repo in Github. I did it through this link http://help.github.com/create-a-repo/. A direct link to create a new repository in your github account is https://github.com/repositories/new It went fine :) – itsraghz Dec 07 '11 at 06:16
  • "https" means "secure HTTP", not "smart HTTP". – John Dvorak Jul 26 '16 at 13:02
  • @Jan Dvorak - I wasn't suggesting that it was! I've added a clarification. – Mark Longair Mar 27 '17 at 21:58
  • Hi Mark. Your sentence *"the "smart HTTP" protocol by using the https:// URL that GitHub shows you for your repository*" is not clear. With your added clarification your answer becomes correct. Please rework your answer in order to make it simple and without ambiguity => Please rephrase the unclear/ambiguous sentences and merge your clarification paragraph within the first paragraph. Cheers – oHo May 01 '17 at 13:18
38

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.

Community
  • 1
  • 1
Abdo
  • 13,549
  • 10
  • 79
  • 98
13

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

Purplejacket
  • 1,808
  • 2
  • 25
  • 43
2

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ParamQuery
  • 21
  • 2
  • 1
    Incorrect, https protocol will not allow pushes. See: "Pro Git" book, section 4.1.4 "HTTP/S Protocol". Link: http://git-scm.com/book/en/v2 – Kevin J. Rice Jan 06 '15 at 22:22
  • @KevinJ.Rice: uhm, where does it say *that*? Github uses the smart HTTP protocol and that allows for pushes *just fine*. – Martijn Pieters Feb 21 '16 at 10:42
1

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1

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.

Cerin
  • 60,957
  • 96
  • 316
  • 522
1

The below cmnds will fix the issue.

 git pull --rebase
 git push
Hariharan AR
  • 1,386
  • 11
  • 20
0

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
rshdev
  • 373
  • 2
  • 8
0

To set https globally instead of git://:

git config --global url.https://github.com/.insteadOf git://github.com/
tokhi
  • 21,044
  • 23
  • 95
  • 105
0

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!

CambridgeMike
  • 4,562
  • 1
  • 28
  • 37
-1

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tiberiu Craciun
  • 3,231
  • 1
  • 13
  • 12