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
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With