4

How do I make git ask for credentials (username+password) every time there's a push?

We have a shared host where a logal git repository is taking care of version-controlling a bunch of files. I want to push the repository to a remote location over http, and ask for the username+password every time (since this is a shared host, this ensures we track who was responsible for the last changes).

I have done:

git init
git remote add origin http://remote.host/the_git_repo

However, when I push, I get an HTTP 401 error and no username/password prompt:

[user@thehost ~]# git push -u origin master error: The requested URL returned error: 401 Unauthorized while accessing http://remote.host/the_git_repo/info/refs

fatal: HTTP request failed

The .git/config file contents:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        askpass = true
[remote "origin"]
        url = http://remote.host/the_git_repo
        fetch = +refs/heads/*:refs/remotes/origin/*

Notes:

  • SSH login is not available for this remote repo
  • I have read the documentation about the SSH_ASKPASS and GIT_ASKPASS environment variables, but it is not clear how to use them (export GIT_ASKPASS=1 does nothing)
  • This is similar to this question, the difference is that the repository was just created and noone has input any credentials yet
Community
  • 1
  • 1
André Fernandes
  • 2,335
  • 3
  • 25
  • 33
  • Did you try `git remote add origin http://user@remote.host/the_git_repo`? – Jeremy Fortune Oct 08 '15 at 01:49
  • That won't do it. The pushes have to be authenticated with the user that did the changes (the local repository is in a shared location). That way, either everyone pushes with the same user, or they'll have to change `.git/config` every time. – André Fernandes Oct 08 '15 at 09:45
  • I guess I missed that this was a shared host. So you're tracking who did what changes not by who committed them, but by who pushed them? – Jeremy Fortune Oct 08 '15 at 21:02

0 Answers0