Skip to content

Instantly share code, notes, and snippets.

@NileshPatel17
Last active October 18, 2021 12:58
Show Gist options
  • Save NileshPatel17/f207da11c9b1f379e3ff4509cb0279f8 to your computer and use it in GitHub Desktop.
Save NileshPatel17/f207da11c9b1f379e3ff4509cb0279f8 to your computer and use it in GitHub Desktop.
git-multiple-accounts

git-multiple-accounts

step 1:

  1. edit ~/.gitconfig

cat ~/.gitconfig

[user]
   name = Nilesh Patel
   email = [email protected]
[filter "lfs"]
   required = true
   clean = git-lfs clean -- %f
   smudge = git-lfs smudge -- %f
   process = git-lfs filter-process
[init]
   defaultBranch = main

add following to the end of the file

.gitconfig
[user]
	name = Nilesh Patel
	email = [email protected]
[filter "lfs"]
	required = true
	clean = git-lfs clean -- %f
	smudge = git-lfs smudge -- %f
	process = git-lfs filter-process
[init]
	defaultBranch = main
[includeIf "gitdir:~/clients/blanclabs/"]
    path = ~/clients/blanclabs/.git-blanclabs.conf
[includeIf "gitdir:~/clients/work"]
    path = ~/side-projects/.git-work.conf
Notes
  1. The order is depended, the last one who matches "wins".
  2. the / at the end is needed - e.g. "gitdir:D:/work" won't work.
  3. the gitdir: prefix is required.

Step 2:

create a new file .git-blanclabs.conf at ~/clients/blanclabs/ with following contents.

I want to override only email. If you want to override name as well, add it. You can override default branch as well.
[user]
  email = [email protected]
[init]
  defaultBranch = dev

testing with new directory:

  1. cd to ~/clients/blanclabs/ cd ~/clients/blanclabs/
  2. create a directory: mkdir test
  3. cd to test cd test
  4. init git git init
  5. add a new file touch aa.txt
  6. add file to staging `git add .```
  7. commit git commit -m"first commit"
  8. run git log to see the author `git log```
commit 33db096c6778b36704b03a9b80583e96e5dce7c4 (HEAD -> dev)
Author: Nilesh Patel <[email protected]>
Date:   Fri Oct 1 12:56:29 2021 +0530

    first commit
(END)
  1. you can also verify by running git config -l
credential.helper=osxkeychain
user.name=Nilesh Patel
[email protected]
filter.lfs.required=true
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
init.defaultbranch=main
includeif.gitdir:~/clients/blanclabs/.path=~/clients/blanclabs/.git-blanclabs.conf
[email protected]
init.defaultbranch=dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment