Trace: git-config

Git config

Default branch

Initialize repos with main as default branch:

git config --global init.defaultBranch main
  

Alternatively with git versions lower than 2.28 click here

Load dynamically git configurations per context with: [includeIf]

It is possible to load git configuration per context with [includeIf…]

I used to split the git repos in my directory tree into several contexts, like

.
└── gits
    ├── general
    ├── priv
    │   └── .gitconfig
    └── work
        └── .gitconfig

where work are repos I need for work, priv are my personal ones and general neither nor. For work I have different settings than for priv - like user.email, user.name and similar. To anything else not configured explicetely this way the general settings from my global ~/.gitconfig apply. The relevant part of my ~/.gitconfig is the following:

[includeIf "gitdir:~/gits/priv/"]
	path = ~/gits/priv/.gitconfig
 
[includeIf "gitdir:~/gits/work/"]
	path = ~/gits/work/.gitconfig

which causes git to load the configuration in the root of the priv and/or work folder when I work on repositories below those folders.

Click to open information about how to create and/or use a config file with custom location and/or custom name

And from now the settings in the custom .gitconfig files will overrule same settings from the global ~/.gitconfig - and additional settings will extend it.

pub/tech/git/git-config.txt · Last modified: 2024/02/18 11:56