# bug report: cloning private repo to absolute path doesn't work if gitconfig has includeIf directives

2 messages from 2023-07-12 to 2023-07-13. Participants: Juan M Uys, brian m. carlson.
Thread: https://gitlist.dev/t/59977

## Juan M Uys, 2023-07-12 16:21

Subject: bug report: cloning private repo to absolute path doesn't work if gitconfig has includeIf directives
Message-ID: <CADfPAEbgfvnS6JTwa5Y1Zt7gQ31GRUyjjjpX9mmpcwxsaTLPGw@mail.gmail.com>
URL: https://gitlist.dev/e/CADfPAEbgfvnS6JTwa5Y1Zt7gQ31GRUyjjjpX9mmpcwxsaTLPGw%40mail.gmail.com

```
The entire description is in the attachment.


Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)

What did you expect to happen? (Expected behavior)

I want to clone a private repo to an absolute path (regardless of whether the path exists or not), and it doesn't work. E.g.

What happened instead? (Actual behavior)

ˋˋˋ
% git clone --depth=1 'git@github.com:myorg/myprivaterepo.git' '/tmp/some-new-folder'
Cloning into '/tmp/some-new-folder'...
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
ˋˋˋ

However, if I remove the last argument, it works, and clones to the current directory:

ˋˋˋ
% git clone --depth=1 'git@github.com:myorg/myprivaterepo.git'
Cloning into 'myprivaterepo'...
remote: Enumerating objects: 99, done.
remote: Counting objects: 100% (99/99), done.
remote: Compressing objects: 100% (87/87), done.
remote: Total 99 (delta 7), reused 77 (delta 7), pack-reused 0
Receiving objects: 100% (99/99), 5.66 MiB | 4.71 MiB/s, done.
Resolving deltas: 100% (7/7), done.
ˋˋˋ

Public repos work if I specify an absolute path as the destination directory, e.g.:

ˋˋˋ
% git clone --depth=1 'https://github.com/git/htmldocs.git' '/tmp/git-html-docs'
Cloning into '/tmp/git-html-docs'...
remote: Enumerating objects: 1028, done.
remote: Counting objects: 100% (1028/1028), done.
remote: Compressing objects: 100% (920/920), done.
remote: Total 1028 (delta 312), reused 455 (delta 107), pack-reused 0
Receiving objects: 100% (1028/1028), 3.24 MiB | 4.13 MiB/s, done.
Resolving deltas: 100% (312/312), done.
ˋˋˋ

What's different between what you expected and what actually happened?

I'm getting an "access rights" error, instead of my repo being cloned.

Anything else you want to add:

I separate my git organisations with different SSH keys with the help of a global git config:

ˋˋˋ
init]
        defaultBranch = main
[user]
        email = opyate@gmail.com
        name = Juan Uys
[core]
        excludesfile = /home/opyate/.gitignore
        editor = vim
        pager = less -FRX

[includeIf "gitdir:/home/opyate/Documents/code/org1/"]
        path = /home/opyate/Documents/code/org1/gitconfig
[includeIf "gitdir:/home/opyate/Documents/code/org2/"]
        path = /home/opyate/Documents/code/org2/gitconfig
[filter "lfs"]
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
        required = true
ˋˋˋ

And then each org's gitconfig typically looks like:

ˋˋˋ
[user]
        name = Juan Uys
        email = juan.uys@org1.com


[core]
        sshCommand = "ssh -i ~/.ssh/org1/id_ed25519"
ˋˋˋ


Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.41.0
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 5.15.0-76-generic #83~20.04.1-Ubuntu SMP Wed Jun 21 20:23:31 UTC 2023 x86_64
compiler info: gnuc: 9.4
libc info: glibc: 2.31
$SHELL (typically, interactive shell): /usr/bin/zsh


[Enabled Hooks]
not run from a git repository - no hooks to show

```

## brian m. carlson, 2023-07-13 00:21

Subject: Re: bug report: cloning private repo to absolute path doesn't work if gitconfig has includeIf directives
Message-ID: <ZK9Dgqgy5qRDKhG0@tapette.crustytoothpaste.net>
URL: https://gitlist.dev/e/ZK9Dgqgy5qRDKhG0%40tapette.crustytoothpaste.net
In-Reply-To: <CADfPAEbgfvnS6JTwa5Y1Zt7gQ31GRUyjjjpX9mmpcwxsaTLPGw@mail.gmail.com>

```
On 2023-07-12 at 16:21:38, Juan M Uys wrote:
> What happened instead? (Actual behavior)
> 
> ˋˋˋ
> % git clone --depth=1 'git@github.com:myorg/myprivaterepo.git' '/tmp/some-new-folder'
> Cloning into '/tmp/some-new-folder'...
> ERROR: Repository not found.
> fatal: Could not read from remote repository.
> 
> Please make sure you have the correct access rights
> and the repository exists.
> ˋˋˋ
> 
> However, if I remove the last argument, it works, and clones to the current directory:
> 
> ˋˋˋ
> % git clone --depth=1 'git@github.com:myorg/myprivaterepo.git'
> Cloning into 'myprivaterepo'...
> remote: Enumerating objects: 99, done.
> remote: Counting objects: 100% (99/99), done.
> remote: Compressing objects: 100% (87/87), done.
> remote: Total 99 (delta 7), reused 77 (delta 7), pack-reused 0
> Receiving objects: 100% (99/99), 5.66 MiB | 4.71 MiB/s, done.
> Resolving deltas: 100% (7/7), done.
> ˋˋˋ

Is the directory you're cloning to the same as above?  Do you see the
same behaviour as above if you switch to /tmp and run this:

  $ git clone --depth=1 'git@github.com:myorg/myprivaterepo.git' some-new-folder

> I separate my git organisations with different SSH keys with the help of a global git config:
> 
> ˋˋˋ
> init]
>         defaultBranch = main
> [user]
>         email = opyate@gmail.com
>         name = Juan Uys
> [core]
>         excludesfile = /home/opyate/.gitignore
>         editor = vim
>         pager = less -FRX
> 
> [includeIf "gitdir:/home/opyate/Documents/code/org1/"]
>         path = /home/opyate/Documents/code/org1/gitconfig
> [includeIf "gitdir:/home/opyate/Documents/code/org2/"]
>         path = /home/opyate/Documents/code/org2/gitconfig
> [filter "lfs"]
>         clean = git-lfs clean -- %f
>         smudge = git-lfs smudge -- %f
>         process = git-lfs filter-process
>         required = true
> ˋˋˋ
> 
> And then each org's gitconfig typically looks like:
> 
> ˋˋˋ
> [user]
>         name = Juan Uys
>         email = juan.uys@org1.com
> 
> 
> [core]
>         sshCommand = "ssh -i ~/.ssh/org1/id_ed25519"
> ˋˋˋ

My guess is that this is related.  If you're cloning into one of the
directories specified with `includeIf` above, then you'd be using a
specific SSH key to do so.  In such a case, you'd have access to
different things than if you cloned in a different repository.

That would explain why public repositories work: as long as you have
an SSH key valid for _some_ account on GitHub, you can clone any public
repository.
-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA

```
