2

At work, we have Github Enterprise, but sometimes I also pull from the public Github.com. I need to use my work author info for any Github Enterprise activity, but I don't want to confuse my work credentials with my personal credentials when updating Github.com repos that I already have activity on.


As a comparison, I was able to successfully setup different proxy information based on URL as follows:

git config --global http.https://github.com.proxy http://<myworkproxy:port>
git config --global https.https://github.com.proxy http://<myworkproxy:port>

which will use the proxy only when https://github.com is in the remote URL.

This can be verified by entering a real remote URL as follows, and Git will spit out the proxy to be used:

git config --url-match https.proxy https://github.com/<rest of repo URL>

So, I tried the above for user.name and user.email as well:

git config --global user.https://github.com.name <My Github.com user name>
git config --global user.https://github.com.email <My Github.com user email>

This checking my global config file (use git config --global -e to pull it up in an editor), everything appears to be setup correctly:

[user]
    name = <My work user name>
    email = <My work user email>
[user "https://github.com"]
    name = <My github.com user name>
    email = <My github.com user email>

Even if I use git config --url-match user.name https://github.com/<rest of repo URL> it will show me the github.com user name rather than the work user name, so the filtering is working correctly.

However, when I commit with git (whether from a GUI, or directly on the command line), it still always uses my work user.name and user.email.

Is it not possible to URL match the user name and email globally? Or am I doing something wrong here?

I can update the name and email for every repo directly if needed, but I was hoping for a more global solution.

Thanks!

osowskit
  • 5,904
  • 2
  • 29
  • 38
LightCC
  • 9,804
  • 5
  • 52
  • 92
  • the only think I can come up with, is that when committing you're using a git:// URL instead of an https:// one. But I guess you'd already thought on that. – Victor Jalencas Sep 28 '17 at 00:04
  • @VictorJalencas Yeah, it's not that. I've been thinking about this though - when you make a commit it's to the local repo, not to a remote, so I bet Git doesn't do URL matching on the name and email. For example, you could have multiple remotes, or no remote, so why would you always URL match the author info? – LightCC Sep 28 '17 at 00:13
  • yeah, that would make sense. Perhaps you can experiment with a URL starting with `file://` or the name of the parent directory (since it's the closest URL that matches) – Victor Jalencas Sep 28 '17 at 13:51

1 Answers1

3

git doesn't allow you to use a URL match to set the user.name and user.email settings.

URL matching is generally limited to those settings which involve interacting with remote servers, such as the http.* and credential.* settings. If you run git config --help, you can see which settings allow this, because they are documented with the <url> component.

The reason for this is that git doesn't consider the clone or push URLs when setting up non-remote settings.

You can, however, set these on a per-repository basis. If you want to do this automatically, you can set them when you clone by setting up a template directory with an appropriate config file (see git init --help) for each user and using the --template option when you clone. This can be pushed into an alias if you like.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Thanks - that's the info I was looking for. I've not looked at the template options before, I'll look into that. – LightCC Oct 02 '17 at 03:45