Using multiple git user configs with credentials store

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 the same .git-credentials.

Step 1: Separate Work/Personal directories

Create a work and a per…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Bhupesh Varshney 👾

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 the same .git-credentials.

Step 1: Separate Work/Personal directories

Create a work and a personsal directory in your Documents folder. Use these directories to separate your git directories.

  Documents
  ├── work
  │   ├── ...
  │   └── ...
  └── personal
      ├── ...
      └── ...

Step 2: Separate git config for each account

  • Create .gitconfig-personal in the personal dir.
  [credential]
    helper = store
  [user]
    name = Personal_Username
    email = personal_email@domain.com
  [credential "https://github.com"]
    username = Personal_Username
    helper = store
  • Create .gitconfig-work in the work dir.
  [credential]
    helper = store
  [user]
    name = Work_Username
    email = work_email@domain.com
  [credential "https://github.com"]
    username = Work_Username
    helper = store

Step 3: Update global .gitconfig to switch the profile based on directory

  • Update your global config using the 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

Step 4: Register Access Tokens

  https://Personal_Username:PERSONAL_TOKEN@github.com
  https://Work_Username:WORK_TOKEN@github.com

That's it, the next time you pull/push/clone a private repo, git will automatically choose the correct token for each config.


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Bhupesh Varshney 👾


Print Share Comment Cite Upload Translate Updates
APA

Bhupesh Varshney đź‘ľ | Sciencx (2023-02-18T15:05:41+00:00) Using multiple git user configs with credentials store. Retrieved from https://www.scien.cx/2023/02/18/using-multiple-git-user-configs-with-credentials-store/

MLA
" » Using multiple git user configs with credentials store." Bhupesh Varshney đź‘ľ | Sciencx - Saturday February 18, 2023, https://www.scien.cx/2023/02/18/using-multiple-git-user-configs-with-credentials-store/
HARVARD
Bhupesh Varshney đź‘ľ | Sciencx Saturday February 18, 2023 » Using multiple git user configs with credentials store., viewed ,<https://www.scien.cx/2023/02/18/using-multiple-git-user-configs-with-credentials-store/>
VANCOUVER
Bhupesh Varshney đź‘ľ | Sciencx - » Using multiple git user configs with credentials store. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/18/using-multiple-git-user-configs-with-credentials-store/
CHICAGO
" » Using multiple git user configs with credentials store." Bhupesh Varshney đź‘ľ | Sciencx - Accessed . https://www.scien.cx/2023/02/18/using-multiple-git-user-configs-with-credentials-store/
IEEE
" » Using multiple git user configs with credentials store." Bhupesh Varshney đź‘ľ | Sciencx [Online]. Available: https://www.scien.cx/2023/02/18/using-multiple-git-user-configs-with-credentials-store/. [Accessed: ]
rf:citation
» Using multiple git user configs with credentials store | Bhupesh Varshney đź‘ľ | Sciencx | https://www.scien.cx/2023/02/18/using-multiple-git-user-configs-with-credentials-store/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.