0

Imagine you have this git project folder structure:

  • /home/user/gitlab
  • /home/user/github

Is it possible to define somewhere in one place that git auth logic using certificates should be configured for all projects under one of the path correspondingly? And maybe also different user signatures?

Open Food Broker
  • 1,095
  • 1
  • 8
  • 31

1 Answers1

1

For access : you can use your ~/.ssh/config file to set different keys for different servers.

# in your ~/.ssh/config file :

Host github.com
    IdentityFile path/to/github_key

Host gitlab.com
    IdentityFile path/to/gitlab_key

Once set up, any ssh interaction with github.com (resp. gitlab.com) -- e.g : git clone git@github.com:repo, git fetch, git push ... -- will use github_key (resp. gitlab_key) by default.


For git config parameters (e.g : user.name and user.email), you can use includeIf sections (link to docs) as suggested by @choroba :

# in your .gitconfig file :
[includeIf "gitdir:~/github/**"]
    path = ~/path/to/github_conf_file

[includeIf "gitdir:~/gitlab/**"]
    path = ~/path/to/gitlab_conf_file

and set the user.name and user.email values in github_conf_file and gitlab_conf_file.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • if I observe that e.g. git push keeps switching to user/password prompt, are there any error messages to check for? – Open Food Broker Oct 03 '20 at 14:39
  • UPD debugging settings found ```GIT_CURL_VERBOSE=1 GIT_TRACE=1 git pull``` but not helpful. Re-cloning the repo with git@.. was the trick. Thanks! is there a way not to re-clone? – Open Food Broker Oct 03 '20 at 14:47
  • On an existing repo : check the url defined for each remote matches – LeGEC Oct 03 '20 at 18:37