Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local git config not overriding global user for project

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 
like image 634
amacrobert Avatar asked May 27 '16 14:05

amacrobert


People also ask

How does local git config differ from global?

System vs Global vs Local Git config System Git config controls settings for all users and all repositories on your computer. Global Git config controls settings for the currently logged in user and all his repositories. Local Git config controls settings for a specific repository.

What is git config --'global user name?

To set your Git username, run the git config –global user.name command. You should specify both your first and last name but your username can be anything you want to attach to your commits. Your Git username does not need to be the same as your version control username, such as the one you use on GitHub.


2 Answers

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.

like image 55
thekevinscott Avatar answered Oct 02 '22 19:10

thekevinscott


If you are working on OSX with GitHub it might be a certificate problem. Your GitHub certificate, which remembers your user.name and user.email overrides the local config settings. One way to solve it, is to go to your keychain and remove the GitHub certificate.

like image 32
CasperTN Avatar answered Oct 02 '22 18:10

CasperTN