7

I worked alone on a project versioned on Github, so for convenience I put something like this in my ~/.git/config file:

url = https://MYUSERNAME@github.com/COMPANY/PROJECT.git

This way git asks only for password on pull/push. But now more people have to push and pull, so we thought this would make git ask also for user name:

url = https://github.com/COMPANY/PROJECT.git

But instead git asks for nothing now and this is a sample result of git pull:

error: The requested URL returned error: 403 while accessing https://github.com/COMPANY/PROJECT.git/info/refs

fatal: HTTP request failed

How can git be forced to ask for user name and password as expected?

Community
  • 1
  • 1
Rafał G.
  • 1,529
  • 22
  • 35
  • Did you consider [certificate-based authentication](http://scripts.mit.edu/faq/146/how-can-i-avoid-typing-my-password-repeatedly-when-using-git-with-the-smart-http-transport)? – Philipp Oct 29 '13 at 10:19
  • @Philipp I was wondering about trying some other authentication methods, but for now I'd like to make the most basic one work. – Rafał G. Oct 29 '13 at 10:53

2 Answers2

4

I work on some different servers now and I've noticed that this issue affects git 1.7.0.4, but not the newer 1.7.9.5. So anyone experiencing the same problem should upgrade their git if possible.

@jszakmeister suggested asking the git mailing list, but having read this stackoverflow thread and this github page I think there's no point, it looks like a known problem without a good known solution. Github say they recommend git 1.7.10 and people in the stackoverflow discussion suggest things that don't really solve my problem. So I guess the only option is updating your git - let consider that the solution and this question answered.

Community
  • 1
  • 1
Rafał G.
  • 1,529
  • 22
  • 35
  • [Installing Latest version of git in ubuntu](http://stackoverflow.com/questions/19109542/installing-latest-version-of-git-in-ubuntu) – aldel Oct 01 '14 at 03:50
  • Confirmed. Was using 1.7.1 and had this same problem; switched to 2.10.2 and it works fine now, prompting for username and password as desired. – Aaron Wallentine Jan 20 '17 at 02:10
0

Are you using a credential helper? What does git config --get credential.helper show? If it shows something, then perhaps the information is being cached by the credential helper. One way of removing it would be:

printf "protocol=https\nhost=github.com\npath=COMPANY/PROJECT.git\nusername=MYUSERNAME\n\n" |
    git credential fill

It it prompts you for the password, then it's not cached in that particular form. It could be that it was cached without the .git on the end:

printf "protocol=https\nhost=github.com\npath=COMPANY/PROJECT\nusername=MYUSERNAME\n\n" |
    git credential fill

You can remove the credential with:

printf "protocol=https\nhost=github.com\npath=COMPANY/PROJECT.git\nusername=MYUSERNAME\n\n" |
    git credential remove

or, if no '.git' was present on the url:

printf "protocol=https\nhost=github.com\npath=COMPANY/PROJECT\nusername=MYUSERNAME\n\n" |
    git credential remove

Note that the only difference between these two commands and the above commands is that git credential fill became git credential remove. Also, if you post any data that comes from the git credential fill command, make sure to obscure your username and password.

If none of that helps, you may need to look at your ~/.gitconfig. You may have some credential.<url> blocks set up as outlined in this man page. Alternatively, you might be able to use that to alter the username.

John Szakmeister
  • 44,691
  • 9
  • 89
  • 79
  • 2
    We don't have credential helper installed, so it's not it unfortunately. – Rafał G. Oct 29 '13 at 10:49
  • Are you sure? Did you try `git config --get credential.helper`? Most new installs do install one. – John Szakmeister Oct 29 '13 at 10:52
  • Oooh... GitHub may not be behaving correctly here, and outright denying you access instead of prompting for a username. I seem to recall this being an issue. – John Szakmeister Oct 29 '13 at 10:54
  • Hm, GitHub specific issue then... I'll google some more looking for Github this time. As for the credential helper, the command you posted returns nothing, also "git credential fill" returns "git: 'credential' is not a git command." so I'm positive we don't have the helper enabled. – Rafał G. Oct 29 '13 at 11:05
  • @rafal-g this is not github specific, I got the same issue with bitbucket and git 1.7.1 – gorodezkiy Mar 31 '14 at 11:47
  • @antongorodezkiy I was suspecting it too, it seems that it has something to do with git config for the current user on the local server, not with GitHub. But I still wasn't able to resolve it. If I ever do, I'll post a solution here, if you can solve it yourself, please do the same, it'll be much appreciated. – Rafał G. Apr 01 '14 at 16:41
  • Can either one of you report it to the Git mailing list: git@vger.kernel.org? They're very helpful, and can walk you through some troubleshooting steps to help identify the problem. – John Szakmeister Apr 01 '14 at 18:42
  • @rafal-g sure, I will – gorodezkiy Apr 01 '14 at 21:19