How can I change the user on Git Bash?

后端 未结 4 1871
再見小時候
再見小時候 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 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-
       HostName github.com
       User git
       IdentityFile ~/.ssh/id_rsa_user1
       
    # Second account
    Host github.com-   
       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-
    

    You should see the following output:

    Hi ! 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-.

    git remote rm origin
    git remote add origin git@github.com-:/your_username/your_repository.git
    

提交回复
热议问题