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.
git config --global http.https://github.com.proxy http://<myworkproxy:port>
git config --global https.https://github.com.proxy http://<myworkproxy:port>
https://github.com
git config --url-match https.proxy https://github.com/<rest of repo URL>
user.name
user.email
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>
git config --global -e
[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>
git config --url-match user.name https://github.com/<rest of repo URL>
user.name
user.email
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.