Reputation: 10602
I'm currently working on 2 projects, which expect that I configure my local username and email with different data when I push to them. For that I'm updating my config all the time like:
git config --local user.email "[email protected]"
Since they are different repositories, is there a way I could define an local email for each repository?
Maybe in the .gitconfig
?
Upvotes: 407
Views: 356848
Reputation: 141
It can be achieved with below commands,
git config --local credential.helper ""
git push origin master
It asks for username and password for current repo.
Upvotes: 13
Reputation: 18645
...or just edit the .git\config
file and add these three lines somewhere:
[user]
name = YourName
email = [email protected]
Upvotes: 34
Reputation: 12895
For just one repo, go into to the relevant repo DIR and:
git config user.name "Your Name Here"
git config user.email [email protected]
For (global) default email (which is configured in your ~/.gitconfig):
git config --global user.name "Your Name Here"
git config --global user.email [email protected]
You can check your Git settings with:
git config user.name && git config user.email
If you are in a specific repo which you setup a new user/config for (different to global) then it should show that local config, otherwise it will show your global config.
Upvotes: 760
Reputation: 1340
One trick that has been reliably working for me is to set both a global config credential.username
option as well as a local one. They will ask for a password for authentication. This works even for Git Credential Manager say on a Mac. For more information, please see: https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git. So you can cache like at least two different passwords for two different GitHub accounts.
Upvotes: 2
Reputation: 813
I generally tend to keep diff name/email for my company project and personal project(on github)
Run below command in the git repo where you need to specify the user/email
git config user.name <user-name>
git config user.email <user-email>
Upvotes: 10
Reputation: 543
You can confirm that by printing on the terminal:
git config --global user.name
git config user.name
Upvotes: 27