Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go get doesn't work with .gitconfig that references a custom gitconfig

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 [email protected]: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 = [email protected]
[url "[email protected]:"]
        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.

like image 624
Klimbo Avatar asked Dec 18 '20 10:12

Klimbo


People also ask

What is ~/ Gitconfig?

gitconfig is used to store a per-user configuration as fallback values for the . git/config file. The file /etc/gitconfig can be used to store a system-wide default configuration. The configuration variables are used by both the Git plumbing and the porcelains.

Why is there no Gitconfig file?

The reason they can't find gitconfig is simply because it's nowhere to be found. When developers install Git, the various Git configuration files won't automatically create. Files like gitconfig and . gitconfig are only created when they're first used.


1 Answers

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 "[email protected]:company/"]
        insteadOf = https://bitbucket.org/company/

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

like image 58
bk2204 Avatar answered Oct 02 '22 03:10

bk2204