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.
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
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
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!
To set https
globally instead of git://
:
git config --global url.https://github.com/.insteadOf git://github.com/
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.)