LightCC LightCC - 3 years ago 181
Git Question

Can I use different author info for Git repo, depending on URL

At work, we have Github Enterprise, but sometimes I also pull from the public 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 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. http://<myworkproxy:port>
git config --global https. http://<myworkproxy:port>

which will use the proxy only when
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<rest of repo URL>

So, I tried the above for
as well:

git config --global user. <My user name>
git config --global user. <My 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:

name = <My work user name>
email = <My work user email>
[user ""]
name = <My user name>
email = <My user email>

Even if I use
git config --url-match<rest of repo URL>
it will show me the 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

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.


Answer Source

git doesn't allow you to use a URL match to set the and 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download