how to access github using a user name that is local to the current git folder?
I am getting "permission denied to user steve" error on "git push -u origin main" command.
But "steve" is my --global user name. In this repo, I want to use a 2nd user name and email. To set the user name in this folder, I ran:
git config user.name "localsteve"
but I still get the "permission denied to user steve" error.
When I run git config --list, there are two user.name entries:
$ git config --list
user.name=steve
[email protected]
user.name=localsteve
[email protected]
remote.origin.url=https://github.com/xxx/steve.git
I ran "git config --unset user.name "steve". But this has no effect. ( because that is the --global user name? )
How can I pull from a github repo using a user name and email that does not match the --global user.name?
update: I can push to the repo by specifying the user name of the repo in the push command:
git push https://'localsteve'@github.com/xxx/steve.git
But I am prompted to enter the PAT on each push. How to specify the local user name in the .git folder?
CodePudding user response:
The Git FAQ notes that user.name
is the name in commits and has no effect on authentication, and that it is customarily a personal name (e.g., “Pat Doe”) rather than a username.
If you need to use multiple usernames on your system, the Git FAQ also explains how to do that. Typically, you will want to put the username in the URL, and you will want to configure a credential manager to save your credentials. If all of your remote URLs contain a username, Git will distinguish the tokens or other credentials and will choose the right one automatically.
If you're being prompted for credentials after entering them, then you probably haven't set up a credential manager correctly. The Git FAQ also outlines how to do that. The customary credential manager depends on the operating system.