Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overwrite global Git credentials for one repo?

If I set

git config --global credential.username my_username

option, then overwriting it for one repository with --local option gives no difference for it - it still uses global credentials while trying to commit or push. How can I change this?

like image 278
joval Avatar asked May 12 '15 16:05

joval


People also ask

Where are global git-credentials stored?

You can check the credentials stored in the file ~/. git-credentials . For more information, visit git-credential-store - Helper to store credentials on disk.


1 Answers

The repo local config doesn't work for me. After trying all kinds of ways from stackoverflow, finally it works by switching from ssh to https and using credential.helper :

step 1, change git remote from ssh to https:

$ git remote -v
    [email protected]:#####/###.git (push)

$ git remote rm origin
$ git remote add origin https://[email protected]/######/###.git

step 2, let credential.helper to help remember password to avoid annoying repeat asking.

$ git config --global credential.helper cache
$ git config --global credential.helper 'cache --timeout 7200'

By default credentials will be saved in ~/.git-credentials. It will be created and written to.

But please note using this helper will store your passwords unencrypted on disk, protected only by filesystem permissions. If this may not be an acceptable security tradeoff.

like image 69
gary Avatar answered Oct 20 '22 20:10

gary