3

I'm using GIT for my projects. Now I want to integrate it with github, so I created a remote:

git remote add github https://WouterJ@github.com/WouterJ/project.git

But now I need to fill in a password for fetching, something that I don't want. So I decided to use a different url for fetching:

git remote set-url github http://github.com/WouterJ/project.git
git remote set-url --push github https://WouterJ@github.com/WouterJ/project.git

If I run git remote -v I get this:

$ git remote -v
github  http://github.com/WouterJ/project.git (fetch)
github  https://WouterJ@github.com/WouterJ/project.git (push)
origin  http://github.com/WouterJ/project.git (fetch)
origin  http://github.com/WouterJ/project.git (push)

Exactly want I want, I thought. But when I do a push I need to fill in my Username. Why? If I push directly to the url if filled in it works perfectly:

git push https://WouterJ@github.com/WouterJ/project.git master

Works, but

git push github master

Won't work


I also used the git config to set a different push url:

git config remote.github.pushurl https://WouterJ@github.com/WouterJ/project.git

And if I get the pushurl from the config it looks like it is correct:

$ git config remote.github.pushurl
https://WouterJ@github.com/WouterJ/project.git

Also looking at the .git/config file it looks like everything is correct.


Am I missing something here? Is it a bug? I use Git1.7.4, is that wrong?

Wouter J
  • 41,455
  • 15
  • 107
  • 112

2 Answers2

2

I have found how you can solve this, so to aswer my own question:

The trick is to upload to Git1.7.8 (or higher). Now you get this with the same settings and without a _netrc file:

$ git push github master
Password for 'https://WouterJ@github.com/':

$ git fetch github
fetching....

So it looks like the bug is fixed in Git1.7.8 (Release Notes)

Wouter J
  • 41,455
  • 15
  • 107
  • 112
  • 1
    Excellent. +1. I thought you were using Git1.7.4 (which is already higher than 1.7.0 though) – VonC May 06 '12 at 20:18
  • Wait, I have typed Git1.7.0 but mean Git1.7.10.1 (the latest stable release). Thank you, I will edit it – Wouter J May 06 '12 at 20:22
  • Ok, now I get it ;) I was doing tests with 1.7.9 and 1.7.10 without being able to reproduce your issue, so that confirms it. – VonC May 06 '12 at 20:28
  • @VonC, I have done some more research and it looks like this bug is fixed in 1.7.8 ([Release Notes](https://github.com/git/git/blob/master/Documentation/RelNotes/1.7.8.txt#L134-137)) – Wouter J May 06 '12 at 20:36
1

The only missing piece, in order to push to an https GitHub address, is your ~/.netrc file (or %HOME%/_netrc file on Windows) with your GitHub credentials in it.

See "Git - How to use .netrc file on windows to save user and password".

machine github.com
login <login_github>
password <password_github>

See other settings at "Syncing with github".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for your comment, but I don't want to save the password. The problem is when I use the url in the `git push` command I only need to typ the password. What is the difference between typing the url or using remotes `pushurl`? Do I understand the `pushurl` wrong? – Wouter J May 05 '12 at 20:45
  • @WouterJ `git remote set-url --push` and `git config remote.github.pushurl` should be equivalent. Is it possible you have github defined in another config file (a global or system one, as opposed to your local config file)? – VonC May 05 '12 at 21:08
  • Both techniques won't work. The url is saved in the correct file. If I change that url to a local repo it works and the url itself works, but the user SSH part of the pushurl won't work. I also don't know much about git add configs, so a global or system one? What do you mean? – Wouter J May 05 '12 at 21:17
  • @WouterJ see for instance http://stackoverflow.com/questions/4310974/more-than-one-value-for-the-key-user-name-git/4311218#4311218 – VonC May 05 '12 at 23:03
  • if I typ `git config --get-all remote.github.pushurl` I get only the one I have set up for the project. So it looks like there is no github remote in another config file. I have solved it by using the `_netrc` file (but can I save only the username and not the password?) – Wouter J May 06 '12 at 11:42
  • @WouterJ I don't know of a way to save only the username, beside including it in the https address, except in your case, it doesn't seem to work... Maybe don't include the `password` field in the `_netrc` file, but it might then ask for username and password. – VonC May 06 '12 at 12:32
  • thank you for your help. It seems like I couldn't save only the username, so I have saved them both. Is it a bug that the username in the https address won't work? – Wouter J May 06 '12 at 12:43
  • @WouterJ it seems like a bug. Putting only the username should work. – VonC May 06 '12 at 14:15