How can I change the user on Git Bash?

后端 未结 4 1868
再見小時候
再見小時候 2020-12-23 02:19

I want to sign out an actual user so I can sign in with another user.

What I see in Git bash is:

MINGW64 ~/Documents/NetBeansProjects/Const         


        
相关标签:
4条回答
  • 2020-12-23 02:39

    For Mac Users

    I am using Mac and I was facing the same problem while I was trying to push a project from Android Studio. The reason for that is another user had previously logged into GitHub and his credentials were saved in Keychain Access.

    The solution is to delete all the information store in keychain for that process

    0 讨论(0)
  • 2020-12-23 02:43

    For Mac Users

    I am using Mac and I was facing same problem while I was trying to push a project from Android Studio. The reason for that other user had previously logged into Github and his credentials were saved in Keychain Access.

    You need to remove those credentials from Keychain Access and then try to push.

    Hope it help to Mac users.

    0 讨论(0)
  • 2020-12-23 02:58

    Check what git remote -v returns: the account used to push to an http url is usually embedded into the remote url itself.

    https://Fre123@github.com/...
    

    If that is the case, put an url which will force Git to ask for the account to use when pushing:

    git remote set-url origin https://github.com/<user>/<repo>
    

    Or one to use the Fre1234 account:

    git remote set-url origin https://Fre1234@github.com/<user>/<repo>
    

    Also check if you installed your Git For Windows with or without a credential helper as in this question.


    The OP Fre1234 adds in the comments:

    I finally found the solution.
    Go to: Control Panel -> User Accounts -> Manage your credentials -> Windows Credentials

    Under Generic Credentials there are some credentials related to Github,
    Click on them and click "Remove".

    That is because the default installation for Git for Windows set a Git-Credential-Manager-for-Windows.
    See git config --global credential.helper output (it should be manager)

    0 讨论(0)
  • 2020-12-23 03:01

    For any OS

    This helped me so I'll put it here, just in case. Once you are done with adding the rsa keys for both the accounts, add a config file in your .ssh directory for both the accounts (.ssh/config)

    # First account
    Host github.com-<FIRST_ACCOUNT_USERNAME_HERE>
       HostName github.com
       User git
       IdentityFile ~/.ssh/id_rsa_user1
       
    # Second account
    Host github.com-<SECOND_ACCOUNT_USERNAME_HERE>   
       HostName github.com
       User git
       IdentityFile ~/.ssh/id_rsa_user2
    

    Make sure you use the correct usernames and RSA files. Next, you can open the terminal/git bash on the repository root and check which account you would be pushing from

    git config user.email
    

    Suppose this returns the first user email and you want to push from the second user. Change the local user.name and user.email :

    git config user.name "SECOND_USER"
    git config user.email "SECOND_USER@example.com"
    

    (This won't change the global config and you can have the first user set up as the global user). Once done, you can confirm with git config user.email and it should return the email of the second user. You're all set to push to GitHub with the second user. The rest is all the same old git add , git commit and git push. To push from the first user, change the local user.name again and follow the same steps. Hope it helps :)


    If the above steps are still not working for you, check to see if you have uploaded the RSA keys within GitHub portal. Refer to GitHub documentation:

    Then, clear your ssh cached keys Reference

    ssh-add -D
    

    Then add you 2 ssh keys

    ssh-add ~/.ssh/id_rsa_user1
    ssh-add ~/.ssh/id_rsa_user2
    

    Then type in your terminal:

    ssh -T git@github.com-<SECOND_ACCOUNT_USERNAME_HERE>
    

    You should see the following output:

    Hi <SECOND_USERNAME>! You've successfully authenticated, but GitHub does not provide shell access.
    

    Then, assign the correct remote to your local repository. Make sure you put the same username as the one you gave in your .ssh/config file next to Host. In the following case git@github.com-<SECOND_ACCOUNT_USERNAME_HERE>.

    git remote rm origin
    git remote add origin git@github.com-<SECOND_ACCOUNT_USERNAME_HERE>:/your_username/your_repository.git
    
    0 讨论(0)
提交回复
热议问题