Use different user.email and user.name for git config based on remote cloning url

I tune their global properties ~/.gitconfig user.name, and user.emailas follows:

git config --global user.email "mkobit@example.com" 
git config --global user.name "mkobit"

This is the default configuration that I want to use for personal projects, open source content, etc.

When I work on a project from a specific domain, for example, a corporate domain, I configure it for each repository, when I clone it so that it uses a different user.name/ user.email:

git clone ssh://git@git.mycorp.com:1234/groupA/projectA.git
cd projectA
git config user.email "mkobit@mycorp.com"
git config user.name "m.kobit"

One suitable option is to set an alias for cloning such repositories:

git config --global alias.clonecorp 'clone \ 
        -c user.name="m.kobit" -c user.email="mkobit@mycorp.com"'
git clonecorp ssh://git@git.mycorp.com:1234/groupA/projectA.git

, , . , - .

Git , (mycorp.com ) ?

+14
3

Git 2.13 . 2.13 . , .

, :

~/.gitconfig ~/.gitconfig :

[includeIf "gitdir:~/work/"]
    path = .gitconfig-work
[includeIf "gitdir:~/play/"]
    path = .gitconfig-play

:

$ cat ~/.gitconfig-work
[user]
name = Serious Q. Programmer
email = serious.programmer@business.example.com

$ cat ~/.gitconfig-play
[user]
name = Random J. Hacker
email = rmsfan1979@example.com

Git 2.8 user.useconfigonly, , user.email user.name user.name. Github:

, , , Git , - , , , , Git, . . Git , , , . - , , , .

Git , , user.name user.email, :

git config --global user.useconfigonly true

, URL- , , .

+9

: , ... git -hook, : https://github.com/DrVanScott/git-clone-init

user.email user.name git clone.

0

, , , ,

Git 2.22 (Q2 2019), IncludeIf :

. 19e7fda (26 2019 .) pclouds (pclouds).
( Junio C Hamano - gitster - 078b254, 22 2019 .)

config: ** includeIf

wildmatch() includeIf gitdir WM_PATHNAME.
" * " , " ** " ( " * " ) :

" /**/ " .
' foo/**/bar ' ' foo/bar '.

' /*/ ', , wildmatch WM_PATHNAME, ( ' * ' ).
, " foo/*/bar " " foo/bar ".
" foo//bar ".

, wildmatch() , ' /**/ ', .
, ' * ' , , , , . .

0

Source: https://habr.com/ru/post/1622789/