I have multiple accounts on different public git hostings (github, gitlab, etc) and corporate git hosting.
The problem is that I constantly forget to change my identity:
git config --local user.email "[email protected]"
git config --local user.name "Name"
for each project and my default global configuration (github account) goes into my corporate commits and commits on other git hostings (and even into commit from another account on github) creating a real mess.
Is there any convenient method to stop forgetting to specify account after git clone?
You could unset your global configuration and always apply the user config locally. When you forget to do so, you will get a warning message telling you to configure it.
You could make aliases to help you (untested):
git config --global alias.personal '!git config --local user.email "[email protected]"; git config --local user.name "Name"'
git config --global alias.work '!git config --local user.email "[email protected]"; git config --local user.name "Name"'
So you could then do:
git clone [work project]
cd [work project]
git work
git clone [home project]
cd [home project]
git home
Ideally you could change the built in behaviour of git clone with an alias, but that's not possible. There are workarounds here: https://stackoverflow.com/a/24266749/3408, so you could use that to change git clone to a script that prompted you to choose an identity after the clone operation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With