7

Using git config user.email "some@email.com" sets user email in global config file.

Using git config --global user.email "some@email.com" or git config --local user.email "some@email.com" (from within a repo) throws:

"error: only one config file at a time."

My global .gitconfig:

[color]
  ui = auto
[user]
  name = My Name
  email = my@email.com
[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
  lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset' --abbrev-commit
  type = cat-file -t
  dump = cat-file -p
[push]
  default = simple
[core]
  autocrlf = true

What should I change to be able to have separate user.name/email for global config and local/repo config?

Saran
  • 3,845
  • 3
  • 37
  • 59
  • "`git config user.email "some@email.com"` sets user email in global config file". **That's incorrect**. That command sets up a config for whichever repo you're currently in. If you want to set the global user version of that, you need to use the `--global` flag. See also [Where is git config coming from?](http://stackoverflow.com/questions/17756753/where-is-git-config-coming-from). Also, using the `--global` flag from when a repo shouldn't throw errors...there must be something else that's wrong. –  Apr 03 '14 at 20:50
  • @Cupcake, that's correct, in theory and on this PC, but when I tested it on my other PC, `git config user.email "some@email.com"` changed the email in the **global** git config file. I know mistakes like that can happen, but I tested it several times (there) before I posted. – Saran Apr 03 '14 at 21:10
  • Just updated Git to 1.9.0 and checked again: same thing happens on the PC the error/question is originally reported. – Saran Apr 17 '14 at 09:50

2 Answers2

11

git config --global does not seem to work when the environment variable GIT_CONFIG is set.

Try to unset GIT_CONFIG and then list your global config with

unset GIT_CONFIG
git config --global --list
dpat
  • 253
  • 3
  • 9
  • This is strange. Is there way to set config when we add GIT_CONFIG? – Priyank Thakkar Sep 12 '19 at 03:42
  • @priyank-thakkar: see the man page of git-config(1). "Take the configuration from the given file instead of .git/config". (tuk0z below quotes the man page section too.) – dpat Sep 16 '19 at 05:40
0

Havin come to a similar issue after setting up $GIT_CONFIG, I fully confirm @dpat's answer.

git help config:

ENVIRONMENT
    GIT_CONFIG
       Take the configuration from the given file instead of .git/config. Using the
       "--global" option forces this to ~/.gitconfig. Using the
       "--system" option forces this to $(prefix)/etc/gitconfig.

is simply missleading (ie used for local repo, not --global). Git checks for the global configuration only in the four places that @Cupcake linked to.

tuk0z
  • 578
  • 4
  • 13