- Update Mar 2nd, 2025: Add signing commits
What is it?
Each time you create or clone a Git repository, you need to configure the user.name and user.email (and SSH for private repos).
I often forget to do this, and sometimes I don’t remember my no-reply email address. Here’s a solution.
With profile configurations, you can control the necessary settings for each workspace (directory).
Git profile
Create a separate file with specific configurations for the profile. Here I create it at ~/.config/git/personal.config. Do replace with yours.
[user]
email = 41385034+fixthebug@users.noreply.github.com
name = fixthebug
[core]
sshCommand="ssh -i ~/.ssh/personal"
The sshCommand profile provides the SSH key for private repositories. You can use this in combination with git ssh config to pull and push code seamlessly.
Setup profiles in .gitconfig
Append these lines at the end of your ~/.gitconfig
[include]
path = "~/.config/git/personal.config"
[includeIf "gitdir:~/work1/"]
path = "~/.config/git/work1.config"
[includeIf "gitdir:~/work2/"]
path = "~/.config/git/work2.config"
Explain:
- The first
includetells Git to apply the personal profile for every path. This is considered the default profile. - The
includeIfdirectives tells git to apply thework1.configfor every path under~/work1/, andwork2.configfor subfolders of~/work2/
Sign commits
To sign commits, you can add the following lines to the profile configuration.
(Or run git config --global commit.gpgSign true to enable it globally.)
[user]
email = 41385034+fixthebug@users.noreply.github.com
name = fixthebug
signingkey = ~/.ssh/personal
[core]
sshCommand="ssh -i ~/.ssh/personal"
[gpg]
format = ssh
[commit]
gpgsign = true
On github, add new ssh public key with key type “Signing key”
Conclusion
That’s it! Now, each time you create or clone a new project. Git will automatically determine the correct profile for you! 😎
