79775066

Date: 2025-09-25 16:04:12
Score: 0.5
Natty:
Report link

It's been a few years since the question was asked, but since no good answer emerged, here's how I do it:

Overview - use git's global config

I use git's global config to store remote config blocks with fetch and push URLs, fetch and push refspecs, custom branch.<name>.remote routes, merge settings, etc.

The global config contains a config file per project, which gets included into $HOME/.gitconfig conditionally using [Include] and [IncludeIf] blocks.

Example:

[includeIf "gitdir:ia2/website/.git"]
    path=ia2/website.config

[includeIf "onbranch:cf/"]
    path=cloudflare-tests.config

In this example, the file $HOME/.gitconfigs/ia2/website.config is automatically included when I work on files in the $HOME/proj/ia2/website directory, which is the website for the ia2 project.

Also, in any project, I can create a branch named "cf/..." which causes the cloudflare-tests.config file to be included in git's configuration, which routes that branch to a repo I have connected to Cloudflare Pages. This allows any of my project to be pushed to a Cloudflare Pages site by simply creating an appropriate "cf/" branch in that project.

How the .gitconfigs scheme works

The local config (ie, the .git/config file present in each clone) doesn't contain any repo configuration, other than things that accidentally end up there. Any settings I want to keep and duplicate on other machines are moved from the local .git/config to the global $HOME/.gitconfigs/$PROJECT.config file.

Since all configs for all my projects live under the same $HOME/.gitconfigs directory, this directory is itself a git repository, which I push to github, and fetch on all machines where I need it.

Keeping all cloned repos on synchronized git config

I have a repository named .gitconfigs at github, and I clone this in the $HOME directory of every machine I develop on.

Each one of the projects I'm working on has its corresponding $project.config file maintained in a branch with the same name as the project, and there are some config files that are included in all projects, like the cloudflare example I gave above.

Configs for private projects

The scheme is capable of maintaining a mix of private and public projects. Configs for public projects is pushed to my public .gitconfigs repo, and the private projects get pushed elsewhere. In a company setting, your devteam might maintain a .gitconfigs private repo for.

My implementation of the solution

You're welcome to inspect or fork my .gitconfigs repo at https://github.com/drok/.gitconfigs - give me a click-up if this helps you, and I welcome pull-requests. I currently have public configs for curl, git, transmission, gdb and internet archive. One benefit of sending a PR is that I can give you feedback on the whatever project you're adding. I've been using this technique for a year with huge time savings results. No more losing project-specific repo settings for me.

Reasons:
  • Blacklisted phrase (0.5): I need
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Jaredo Mills