Sometime you may face the situation when you want to commit under different github profiles/accouts, e.g. at office you use company accout google-john-doe and at home you want to create super-secret projects under your persona github accout john-doe and also you do it all on MACBOOK.
To do the actions described above you need to:
- drop ~/.git-credentials folder
- rewrite ~/.gitconfig file like
[user]
email = {email}
name = {user}
[credential]
helper = store
[push]
default = current
- as far as you use macbook drop github note in keychain
All this stuff is a long stroy...so I introduce a small fency script written ib python 2.7 to do all this for you
- clone the repo
git clone https://github.com/dzhitomirsky/github-prfile-switcher- add next env variables (potensially you will need sudo mode - so add them to ~/.bashrc and visudo)
HOME_USER
HOME_EMAIL
WORK_USER
WORK_EMAIL
if you want to do it per terminal sessions:
export HOME_USER=super-user
...- call the script
#to setup home env
python gitprofile.py home
#to setup work env
python gitprofile.py work
#work env is used by default
#next line will give the same result as python gitprofile.py work
python gitprofile.py- create ~/bin (if it doesn't exit)
- add bin folder to PATH (if it isn't so), you can also make it in .bashrc to make it constant
export PATH=$PATH:/home/el/bin- copy gitprofile.py to bin
cd github-prfile-switcher
cp gitprofile.py ~/gitprofile- make it executable
chmod +x ~/bin/gitprofile- Call it in any place
gitprofile work #work profile
gitprofile home #home profile
gitprofile #work profile by default