git pushes with wrong user from terminal

前端 未结 22 1400
夕颜
夕颜 2020-12-07 07:51

I have an issue with git and my terminal.

Here\'s a gallery to show you my issue : http://imgur.com/a/6RrEY

When I push commits from my terminal, git says I

相关标签:
22条回答
  • 2020-12-07 08:01

    What worked for me was to use the Github repo's https URL instead of the ssh URL. I went to the Github project page and copied the https URL into my clipboard, and then pasted it into the second command below:

    git remote rm origin
    git remote add origin https://[...]
    
    0 讨论(0)
  • 2020-12-07 08:01

    clearing keychain didn't help... I had to ssh-add -D and re-add the key with ssh-add <keyfile>

    0 讨论(0)
  • 2020-12-07 08:01

    I solved this problem removing (or renaming to *.bak) the id_rsa and id_rsa.pub file on MacOS High Sierra. Idea from here.

    I have custom host redirects in ~/.ssh/config that should be applied but used wrong user before I renamed the two files...

    0 讨论(0)
  • 2020-12-07 08:04

    I had a similar issue and it turned out that the problem was the fact that the public key file contained my email address on the last line. That seemed to override the User setting in my config. As soon as I removed my email from the .pub file (and re-uploaded to my repo) Git connected using the correct user.

    0 讨论(0)
  • 2020-12-07 08:07

    it looks like my terminal does the commits with my username, but pushes them with the other one

    Author and committer name and email (which are important for GitHub) are derived from:

    git config user.name
    git config user.email
    

    However, as mentioned in git config and git commit-tree, those values can be overridden by environment variables:

    GIT_AUTHOR_NAME
    GIT_AUTHOR_EMAIL
    GIT_COMMITTER_NAME
    GIT_COMMITTER_EMAIL
    

    So double-check those variables.

    Things work back normally if I force the user in the .git/config of a repository but I don't think that's the good option.

    But it should be a good solution.
    When using an https url, I always specify the user in it to make sure the authentication is done with the right user.

    http://USER@github.com/USER/REPO.git
    
    0 讨论(0)
  • 2020-12-07 08:08

    I just had this problem at work. The builtin git that ships with mac or comes when you install xcode caches git credentials in keychain. The fix for me was to:

    start keychain access (start spotlight via cmd + space, type keychain, press enter)

    Under keychains on the upper left, select "login" Under category on the left, select "passwords"

    find the name "github" and delete it.

    0 讨论(0)
提交回复
热议问题