Git using alternate userid although git config and

2020-07-24 06:36发布

问题:

I have two github ids: javadxx and stephencompanyid.

While attempting to push to the github repo shown in the screenshot below it seems the incorrect userid were applied: the intention is to use the javadxx but the error message seem to indicate the other one were applied.

Here are the remote refs:

$git remote -v
origin  https://github.com/javadxx/jfreechart-fse (fetch)
origin  https://github.com/javadxx/jfreechart-fse (push)

Screenshot shows the fork was created under javadxx id:

Here is the command attempted:

6:40:01/jfreechart-fse $git push origin InitFromArray
remote: Permission to javadxx/jfreechart-fse.git denied to stephencompanyid.

The strange thing is that both the .gitconfig and the local git config -l indicate otherwise - i.e. that the javadxx were active.

jfreechart-fse $git config user.name
javadxx
16:48:04/jfreechart-fse $git config user.email
javadxx@<blah>

Inside .gitconfig:

[user]
    name = javadxx 
    email = javadxx@<blah>

I even looked inside the .git folder for any remnants of the other id:

grep companyname .git/*

(no results)

回答1:

The data used by git config (and in your config) file is used for creating the author of the commit. You can put in anything in there - it doesn't matter, there's no verification that this is actually you or any other valid address.

What you are seeing is the authentication for pushing to the server - that's handled separately by Git. Depending on your operating system, your credentials may be cached - this is likely what you're seeing here.

Git comes with a credential helper, which stores your Git credentials in the operating system's credential store (on Windows and on Mac OS X. Linux does not have a secure Git credential store).

To clear the stored authentication data, type the following in a terminal/shell window (hit the ENTER key where it says <ENTER>):

git credential reject<ENTER>
url=https://github.com<ENTER>
<ENTER>

This should clear the stored information, once you try to push again, it should ask for username and password again.

Alternatively, you can use your operating system's credential store (e.g. Keychain Access on Mac OS X) to delete the credentials manually.

More info on the credential storage here:

  • https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage
  • https://help.github.com/articles/caching-your-github-password-in-git/


回答2:

The user.name is for the commits. Not for the actual GitHub https session.

The account used for the GitHub session is entered on git push.
Or it can be part of the url:

git remote set-url https://javadxx@github.com/javadxx/jfreechart-fse
                           ^^^^^^^^

That way, a git push will always require javadxx's password;



标签: git github