Hello All, I am writing this post about how one can use a different user to interact with github. This would be useful when you are working with multiple repositories and you want/need to switch to a different user for a given repo. Since GitHub uses global user for all repo's by default, below steps would be useful to change user:
1. Open explorer and go to the repository for which you want to change the user.
2. Inside root directory of your repo, check for the .git directory and open it.
Note:- .git is a hidden directory, so you need to enable show hidden directories option.Shortcut for mac: cmd + shift + .
3. Look for the config file, open it and add below entry at the end of the file-
[user]
name = your-username
email = your-email
4. Verify user has changed for the current repository
Open the terminal and go to the root directory of the repo and run below command-
git config user.name
The output of the command will be the user you have used in the config file and now all further commands to GitHub from this repo will use this user.
Note:- This change is just for the current repo for other repo's its still the global user.
5. Few other commands around the user and email-
git config --global user.name
Returns global user name that all repo uses.
git config --global user.email
Returns global user email that all repo uses.
git config --global --list
Returns key/value for username and email
Top comments (0)