7

I clone a repository with git clone which has a dependency from another private repo. Inside current repo I try to go get that dependency (go get -u ./...) and it throws me an error:

fatal: could not read Username for 'https://bitbucket.org': terminal prompts disabled

Info

  • I used git clone git@my-name.bitbucket.org:company/repo.git to clone the repo to ~/Desktop/BitBucket/Company directory.
  • I have GOPRIVATE="bitbucket.org/company/*"
  • Everything works without includeIf. If I replace .gitconfig with company .gitconfig it works fine. But I need to manage multiple accounts...
  • The command git config --get user.name (inside the repo) returns My Name. So there is a problem with go get

My main .gitconfig file (in $HOME directory):

[includeIf "gitdir/i:~/Desktop/BitBucket/Company/"]
        path = ~/.git/BitBucket/Company/.gitconfig

My .gitconfig file (for company repo $HOME/.git/BitBucket/Company/.gitconfig):

[user]
        name = My Name
        email = my.name@company.com
[url "git@my-name.bitbucket.org:"]
        insteadOf = https://bitbucket.org/

My ssh config file ($HOME/.ssh/config):

Host my-name.bitbucket.org
  Hostname bitbucket.org
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/keys/BitBucket/my_name/id_rsa

What is my mistake?

I also found this article: https://medium.com/easyread/today-i-learned-fix-go-get-private-repository-return-error-terminal-prompts-disabled-8c5549d89045. You can check the first comment:

FYI, this dont work when using .gitconfig that references a custom .gitconfig-custom. It has to live in ~/.gitconfig….. man that was frustrating.

I tried to move company .gitconfig to home directory (+ renamed it .gitconfig-company). Nothing works.

Klimbo
  • 1,308
  • 3
  • 15
  • 34
  • You would like to use your pro account only for `bitbucket.org/company/*` urls, right ? Have you tried to rewrite only `https://bitbucket.org/company/` urls ? with `git@my-name.bitbucket.org:company/` ? (note : I haven't tested it, not sure this rewting rule works) – LeGEC Jan 03 '21 at 20:46
  • One way to test your setup is : run `git clone https://bitbucket.org/company/repo`, and see if it prompts for a password. You may turn on options to have a more verbose output : `git clone -v ...`, `GIT_TRACE=1 git clone ...`, ... – LeGEC Jan 03 '21 at 20:53
  • @LeGEC I have tried to rewrite url that way, but it didn't solve the issue. – Klimbo Jan 06 '21 at 08:53
  • I have the same problem with go1.17 installed by snap with some one my machine. If I download and set variables manually all work fine. I thing go get us some another .gitconfig file – andreykyz Jun 22 '22 at 12:17

1 Answers1

3

If you're using go get to clone a repository, be aware that the gitdir: and gitdir/i: patterns don't match a repository that's being cloned. That's because the pattern matches directories that are .git directories, and when you're cloning, that .git directory hasn't been created yet.

You could try placing a directive like this into your config instead:

[url "git@my-name.bitbucket.org:company/"]
        insteadOf = https://bitbucket.org/company/

and then setting up a non-work key for Bitbucket if you need to clone other (public) repositories.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Thank you for the response. I clone repository with ```git clone``` and inside this repo I have a dependency which I try to ```go get```. I have tried your solution but unfortunately I see the same error. – Klimbo Dec 18 '20 at 12:16
  • "patterns don't match a repository that's being cloned" seems like a pretty big oversight since cloning is a great example of a time when using personal/business credentials is important. – BM5k Nov 02 '21 at 12:47