How to switch between different git accounts on your machine?

Search for a command to run...

No comments yet. Be the first to comment.
Day 1,2,3 East peasy for now. Day 4 type Address = { address: string; city: string }; type PresentDeliveryList<T> = Record<keyof T, Address>; Learnt that we can make object type using Record and key of. Day 5 type SantasList<A extends readonly any[]...
These tips are from my own experience. Add a backup method. I currently use a program called rclone to backup my stuff. I didn't want to install multiple programs for each cloud provider like Drive, Dropbox, also there is not much support in case of...
This tutorial assume basic knowledge of react-hook-form, check out their helpful tutorials first here if you are new. https://react-hook-form.com/get-started/ Let's take an example of a form where you need to upload files. First we setup react-hook-f...

Recently, I had to create to a stepper form for a website. A stepper form looks like this - source - https://material.angular.io/components/stepper/overview To create this using react-hook-form, follow these steps. Install the necessary dependenci...

You might have a different git account for work and personal use, switching between those accounts can be time-consuming and prone to error. It's also pretty boring to do. You need to change your email, name and even create a ssh key to use with github.
So what can we do about it ? Why automation, of course!
source - https://www.reddit.com/r/ProgrammerHumor/comments/f0ag3i/automation/
I created a python script to automate this stuff.
To use the script you need to create a file called gitConfig.
You can create it using
git config --list > gitConfig
Now you need you copy contents of your .ssh folder to another folder called ssh.
So the config file and ssh folder is all you need to switch a user.
To use the switch_users.py, install the required dependencies, and make sure the folder structure is of the form as given below.
You can switch your git accounts by specifing the folder name.
python3 switch_users.py -f folderName # folderName can be user or work for the tree below.
.
├── switch_users.py
├── user
│ ├── gitConfig
│ └── ssh
│ ├── authorized_keys
│ ├── id_ed25519
│ ├── id_ed25519.pub
│ ├── id_rsa
│ ├── id_rsa.pub
│ └── known_hosts
└── work
├── gitConfig
└── ssh
├── authorized_keys
├── id_ed25519
├── id_ed25519.pub
├── id_rsa
├── id_rsa.pub
└── known_hosts
The code copies the ssh folder for a user, and it sets the email and other keys by reading it from gitConfig.
You can find the whole code here - https://github.com/gajrajgchouhan/Switch_GitConfigs