Local git config not overriding global user for project

amacrobert picture amacrobert · May 27, 2016 · Viewed 10.8k times · Source

I have a global git user configured, but want to use a different user for a single git project.

Within that project, I've used git config --local user.name "localuser" and git config --local user.email "[email protected]" to set the local project's user and email.

However, when I try to push to my remote on github, I get this error:

remote: Permission to localuser/repo.git denied to globaluser.
fatal: unable to access 'https://github.com/localuser/repo.git/': The requested URL returned error: 403

Here's some output that might help with diagnosis:

git remote -v:

github  https://github.com/localuser/repo.git (fetch)
github  https://github.com/localuser/repo.git (push)

git config --list:

user.name=globaluser
[email protected]
...

git config --local --list:

user.name=localuser
[email protected]
...

git config user.name:

localuser

Answer

thekevinscott picture thekevinscott · Mar 23, 2017

I had committed my changes and received a permission denied with my global user. Subsequently setting the local user did nothing, though git config user.name reported the correct local user.

What worked was (courtesy of this google groups thread):

git commit --amend --reset-author

I presume the committed changes had the original author attached.