Using multiple git user configs with credentials store (multiple github accounts)
Posted on 18 Feb, 2023
So, you have decided to have 2 separate accounts for work and personal. Here are steps to follow to use both git configurations simultaneously with same
.git-credentials
.Create a
work
and a personsal
directory in your Documents folder. Use these directories to separate your git directories. Documents
├── work
│ ├── ...
│ └── ...
└── personal
├── ...
└── ...
- Create
.gitconfig-personal
in thepersonal
dir.[credential]helper = store[user]name = Personal_Usernameemail = [email protected][credential "https://github.com"]username = Personal_Usernamehelper = store - Create
.gitconfig-work
in thework
dir.[credential]helper = store[user]name = Work_Usernameemail = [email protected][credential "https://github.com"]username = Work_Usernamehelper = store
- Update your global config using following command.git config --global --edit
- Add the following config.[includeIf "gitdir:~/Documents/work/"]path = ~/Documents/work/.gitconfig-work[includeIf "gitdir:~/Documents/personal/"]path = ~/Documents/personal/.gitconfig-personal
- https://Personal_Username:[email protected]https://Work_Username:[email protected]
That's it, the next time you pull/push/clone a private repo, git will automatically choose the correct token for each config.