I am trying to set up my git config so that I can use a work environment and a personnal environment.
Here is the contents of my ~.gitconfig
file (it so happens work and private are on github):
[url "[email protected]:"]
insteadOf = https://github.com/
[core]
editor = vim
[includeIf "gitdir:~/go/src/github.com/work/"]
path = ~/.gitconfig-work
[includeIf "gitdir:~/go/src/github.com/fzd/"]
path = ~/.gitconfig-private
Here are the contents of both files :
> cat ~/.gitconfig-work
[user]
email = [email protected]
name = realname
signingkey = 454684684654...
[commit]
gpgSign = true
> cat ~/.gitconfig-private
[user]
email = [email protected]
name = fzd
Now let's wander to one of these directories :
> cd ~/go/src/github.com/work/
> git config --get user.email
>
> cd ~/go/src/github.com/fzd/
> git config --get user.name
>
None of the above returned a string.
I was expecting this to work (and it would have solved my troublesome git configuration).
Now, the "fun" part: This config was initially my work config, with only work set properly. When I try to clone a repo from github, wherever I am, it's using my work settings (I haven't restarted since I tried messing around with git - I suppose it's not yet worth it).
Can anyone tell me what I've done wrong with my config ? And why is it using the work parameters ? Is there a kind of cache over the git config ?
[edit]
Here are the contents of my ~/.ssh/config
file:
Host github.com
Hostname ssh.github.com
Port 443
Host *
ServerAliveInterval 10
AddKeysToAgent yes
IgnoreUnknown UseKeychain
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519_work
I do have a key pair for the private repos, I'm not entirely sure how to have both here. Probably something like this.
CodePudding user response:
includeIf
works only in repositories under ~/go/src/github.com/work/
and ~/go/src/github.com/fzd/
but not in a non-repo directory.
To test:
cd ~/go/src/github.com/work/<some-repo>
git config --get user.email