0

I have two different work folders in my computer one is in ~/Documents/work/companyA other is in ~/work/companyB. I wrote conditional gitconfig that is like

[includeIf "gitdir:~/Documents/work/companyA/"]
 path = ~/Documents/work/companyA/.gitconfig
[includeIf "gitdir:~/Documents/work/companyB/"]
 path = ~/Documents/work/companyB/.gitconfig

and the content of both of these files are like

[user]
 name = companyAuser
 email = [email protected]
[url "ssh://git@github-companyA/"]
 insteadOf = https://github.com/

I know this file is being read and git@github-companyA is valid because when I run

git config user.email
ssh -T git@github-companyA

in a directory inside ~/Documents/work/companyA/ both of these commands work correctly.

i am using this config to "go get" from a private repository. Also when i put the URL rewrite command to ~/.gitconfig it works correct. How can i fix this

LeGEC
53.5k5 gold badges69 silver badges127 bronze badges
asked Dec 11, 2023 at 18:08
4
  • any chance that configuration setting could be overridden by another one ? one way to debug your config: git config --show-origin --list Commented Dec 12, 2023 at 5:45
  • Hi thanks for the recommendation i just checked and there is no override Commented Dec 12, 2023 at 10:38
  • ok, and do you see the settings you expect ? (listed from companyA/.gitconfig or companyB/.gitconfig depending on the working directory when you run git config --list) Commented Dec 12, 2023 at 12:35
  • Yes i see all the settings in companyA/.gitconfig Commented Dec 12, 2023 at 14:25

1 Answer 1

1

I misread your question: it is not a git question, it is actually a "go get + git" question.

The locations used by go get are located under the GOMODCACHE directory, not under your working directory.

Here is an illustration using strace on a go get github.com/spf13/cast command (I simulated a private repo by setting GOPRIVATE=github.com/spf13/cast) :

...
[pid 711376] chdir("/home/LeGEC/pkg/mod/cache/vcs/60c669232b830322cfc3d9e570d86c2297d36fdbc38de8ad322b59a3dff47a24") = 0
[pid 711376] execve("/usr/bin/git", ["git", "init", "--bare"], 0xc00046a000 /* 94 vars */) = 0
...
[pid 711377] execve("/usr/bin/git", ["git", "remote", "add", "origin", "--", "https://github.com/spf13/cast"], 0xc00046a300 /* 94 vars */) = 0
...

Possible workarounds:

  • if your can target more specific urls (for example: github.com/companyA/ instead of all of github.com/), you can set replacement urls globally, e.g:
# in your ~/.gitconfig:
[url "ssh://git@github-companyA/companyA/"]
 insteadOf = https://github.com/companyA/
  • use one of the environment variables to specify a gitconfig file, for the duration of one of your go get commands; for example:
GIT_CONFIG_GLOBAL=~/Documents/work/companyA/.gitconfig go get ...
  • set GOMODCACHE to a location under ~/Documents/work/companyA/ when you work on a repo for companyA
    note: this would lead to having several copies of your go cache on your disk
answered Dec 12, 2023 at 19:22
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, I decided to go with the first workaround you recommended

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.