Multiple Git Config Files

Posted on Aug 4, 2023

Configure the ~/.gitconfig global file.

cat > ~/.gitconfig << EOF
[includeIf "gitdir:~/go/src/github.com/digitalnerd/"]
  path = ~/go/src/github.com/digitalnerd/.gitconfig
[includeIf "gitdir:~/go/src/gitlab-your-company/"]
  path = ~/go/src/gitlab-your-company/.gitconfig
EOF

Create a custom configuration as shown below.

cat > ~/go/src/github.com/digitalnerd/.gitconfig << EOF
[user]
  name = digitalnerd
  email = user-name@gmail.com
EOF

Work configuration.

cat > ~/go/src/gitlab-your-company/.gitconfig << EOF
[user]
  name = YOUR-NAME
  email = YOUR-CORP-EMAIL
EOF

Personal

Create personal test repo:

cd ~/go/src/github.com/digitalnerd/
mkdir test-repo
cd test-repo
git init

Check the configuration:

git config -l

Work

Create work test repo:

cd ~/go/src/gitlab-your-company/
mkdir test-repo
cd test-repo
git init

Check the configuration:

git config -l