1

I have two keys to different github account and there is the config ~/.gitconfig:

[user]
        name = example
        email = example@example.com
[pull]
        rebase = true
[rebase]
        autoStash = true
[filter "lfs"]
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
        required = true
[includeIf "gitdir/i:/Users/example/Documents/github_2/"]
    [core]
        sshCommand = "ssh -i ~/.ssh/github2_key"

then, I go to a folder that did not at /Users/example/Documents/github_2/, and run git clone github1_private_project, git told me Please make sure you have the correct access rights

It works to git clone the project from account 'github2' in /Users/example/Documents/github_2/


git version:

% git -v
git version 2.39.2 (Apple Git-143)
afraid.jpg
  • 965
  • 2
  • 14
  • 31
  • As per [this doc](https://git-scm.com/docs/git-config#_example) and [this thread](https://stackoverflow.com/a/61544074/7034621) proper syntax is `gitdir:drive:/some/path`, notice `:` instead of `/` after `gitdir`. – orhtej2 Jun 02 '23 at 11:31
  • 2
    @orhtej2 [`gitdir/i`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-codegitdiricode) is for case-insensitive comparison. It's not drive `I:`. – phd Jun 02 '23 at 12:08
  • 2
    Under `includeIf` there must be a path to an include file. `[core]` terminates `[includeIf]` and starts a new config section which is always (non-conditionally) active. – phd Jun 02 '23 at 12:12
  • @phd Fancy making that an answer? – grg Jun 02 '23 at 15:57

1 Answers1

2

The syntax for includeIf should be (see the docs):

[includeIf "gitdir/i:/Users/example/Documents/github_2/"]
path = </path/to/includeFile>

The syntax

[includeIf "gitdir/i:/Users/example/Documents/github_2/"]
    [core]
        sshCommand = "ssh -i ~/.ssh/github2_key"

actually means

[includeIf "gitdir/i:/Users/example/Documents/github_2/"]
# No `path` hence no include

[core]
    sshCommand = "ssh -i ~/.ssh/github2_key"

where the key core.sshCommand is always (unconditionally) defined.

phd
  • 82,685
  • 13
  • 120
  • 165