Skip to content

Instantly share code, notes, and snippets.

@avoidik
Last active July 14, 2023 09:15
Show Gist options
  • Save avoidik/643fe312f4c99d3601bf4c526886aeb7 to your computer and use it in GitHub Desktop.
Save avoidik/643fe312f4c99d3601bf4c526886aeb7 to your computer and use it in GitHub Desktop.
Organize Git projects based on purpose

It is be possible to organize Git-cloned projects into folders based on work/personal criteria, for instance one folder could be completely dedicated to personal projects, while the other to work related projects.

We could have these two folders in our case:

  • ~/projects/personal/ - personal projects directory
  • ~/projects/work/ - work projects directory

Let's define configuration with sane defaults for git-cloned repositories outside of these two folders.

$ cat ~/.gitconfig
[user]
  name = default.user.name
  email = default.user@email.com
[core]
  autocrlf = input
  editor = nano
  longpaths = true
[pull]
  rebase = true
[init]
  defaultBranch = master
[includeIf "gitdir:~/projects/personal/"]
  path = ~/.gitconfig-personal
[includeIf "gitdir:~/projects/work/"]
  path = ~/.gitconfig-work

Personal projects configuration

$ cat ~/.gitconfig-personal
[user]
 name = personal.user.name
 email = personal.user@email.com

Work projects configuration

$ cat ~/.gitconfig-work
[user]
 name = work.user.name
 email = work.user@email.com

Now, if you would push changes from the personal folder then git will use personal.user@email.com as identity, and work.user@email.com respectively for work folder. For example:

Personal:

$ cd ~/projects/personal/xyz
$ git config --get user.email
personal.user@email.com

Work:

$ cd ~/projects/work/abc
$ git config --get user.email
work.user@email.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment