Git Cheat Sheet · Synchronize
Have one identity per folder
git config --global includeIf."gitdir:~/dev/pro/".path ~/.gitconfig-pro
An includeIf "gitdir:…" rule in ~/.gitconfig applies a configuration file to all the repositories in a folder. You can commit with your work email in ~/dev/pro/ and your personal email elsewhere, without setting anything repository by repository.
What it does
An includeIf rule applies a configuration file to all the repositories in a folder: same commit email and same SSH key (core.sshCommand) without setting anything repository by repository. For Merathon as for git on the command line, a repository's own setting takes precedence over the rule.
A use case
On your work computer, ~/dev/pro/ uses your GitLab account, ~/dev/client/ a self-hosted instance and ~/dev/perso/ GitHub, each with its own email and key.
Warning: If [user] is written after an includeIf rule in ~/.gitconfig, it takes precedence over the profile: the alert points this out. A copy of ~/.gitconfig is kept in ~/.gitconfig.merathon-original and ~/.gitconfig.merathon-backup.
On the command line
git config --global includeIf."gitdir:~/dev/pro/".path ~/.gitconfig-pro- Applies
~/.gitconfig-proto all repositories in~/dev/pro/. git config --file ~/.gitconfig-pro user.email me@example.com- Sets the commit email for this folder.
git config --file ~/.gitconfig-pro core.sshCommand "ssh -i ~/.ssh/id_pro -o IdentitiesOnly=yes"- Uses a specific SSH key for this folder.
git config --show-origin user.email- In a repository: the email used, and the file that sets it.
In Merathon
- Preferences → "Git profiles" → "New profile".
- Choose the folder, the commit name and email, then the account and the SSH key (existing, or to create).
- If the open repository signs with a different email than its profile, an alert appears above the commit summary; "Use profile" removes the repository's own setting.
- Over HTTPS, the token is still chosen from the remote's instance, not from the folder.
Frequently asked questions
Why is my includeIf rule not applied?
The path must end with / to cover the whole folder, and the command must be run in a repository inside that folder. Also check that no [user] is written after the rule in ~/.gitconfig, or in the repository itself.
Which setting wins?
A repository's own setting comes first. In ~/.gitconfig, for a given key, the last value read counts: a [user] placed after the rule wins over the profile.
Does the profile also choose my HTTPS token?
No, not in Merathon: the SSH key follows the folder, but the token is still chosen from the remote's instance.