27

I just started learning about Linux and Git. Im using Linux Mint. I have Git and emacs installed via apt-get.

Im using the following tutorial https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup

it says that there are configuration files in three different places:

  1. /etc/gitconfig file
  2. ~/.gitconfig or ~/.config/git/config file
  3. config file in the Git directory (that is, .git/config) of whatever repository you’re currently using.

I have just started with Git so assume that option 3) is not applicable

I checked both 1) and 2) - i just cannot locate the files anywhere

I googled this with no luck and did sudo find . -name in the root directory

Have no clue what is happening as when i run this

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

(i used my name surname above obviously)

it doesn't give me an error or anything - so where does it write this config data then?? where are these files?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
zamcoot
  • 395
  • 1
  • 3
  • 9
  • Don't you see a `~/.gitconfig` or `~/.config/git/config` *after* typing a `git config --global` command? – VonC Sep 12 '15 at 12:16
  • no they are still not there, i configured user.name and user.email as shown above and the files still not there, so i dont even understand where this data is written... – zamcoot Sep 12 '15 at 12:22
  • Are you doing those command as yourself, or with a sudo in front of them (as root)? What does `echo $HOME` return? – VonC Sep 12 '15 at 12:22
  • I have just tried running them again with sudo and i can see the ~/.gitconfig in my home folder (echo $HOME) if i enable hidden files, my bad.. still learning Linux and have not got used to sudo yet. And though the ~/.gitconfig is almost empty (it should not be as per the tutorial) for some reasons at least i know where it is and how to access it. I will go on with tutorial now again, thanks a lot for your help :) – zamcoot Sep 12 '15 at 12:33
  • the files might not exist before you add any config key but once you set your user.name the file should be created. – Frederic Henri Sep 12 '15 at 12:33
  • 1
    git config --global --edit will edit that file for you – Rolf of Saxony Sep 12 '15 at 12:34
  • For the ```/etc/gitconfig``` file mystery, run As root ```git config --list –show-origin``` and the resulting file will be ```/root/.gitconfig```. Use ```nano``` to view it. I still wonder why i also got the mystery file too. – ColinWa Jan 05 '18 at 11:39

4 Answers4

24

As confirmed by the OP, any git config --global command will create/update ~/.gitconfig.

But as it is an hidden file by default, you would need a ls -alrt to see it.
git config --global -l will list its content.

More generally, git config --list --show-origin shows all config files (and each line of the config data).
With Git 2.26 (Q1 2020), you can add a --show-scope option

git config --list --show-origin --show-scope

That will also print the scope ("local", "global", etc) of all displayed config values.


With Git 2.37 (Q3 2022), confirm that git config --show-scope does show worktree, in addition of local, global, system and command configs.

See commit db7961e (07 Jun 2022) by Glen Choo (chooglen).
(Merged by Junio C Hamano -- gitster -- in commit 21bb385, 13 Jun 2022)

config: document and test the 'worktree' scope

Signed-off-by: Glen Choo

Test that "git config --show-scope"(man) shows the worktree scope, and add it to the list of scopes in Documentation/git-config.txt.

"git config --help"(man) does not need to be updated because it already mentions worktree".

git config now includes in its man page:

(worktree, local, global, system, command).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks - that's correct and i also should've run the commands with sudo – zamcoot Sep 12 '15 at 12:39
  • 2
    @elnurcoot not sure about the `sudo`: that would execute them as `root`, which means a different `HOME`. Running them *without* `sudo` should put the `.gitconfig` in `$HOME` (do a `echo $HOME`, without `sudo`). – VonC Sep 12 '15 at 12:41
  • well echo $HOME with or without sudo returns the same directory for me, and the thing is - only after i did run the commands with sudo i could locate the ~/.gitocnfig file among the hidden files in my home directory.. – zamcoot Sep 12 '15 at 12:45
  • @elnurcoot what does a `id -a` return? – VonC Sep 12 '15 at 12:59
  • uid=1000(elnur) gid=1000(elnur) groups=1000(elnur),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),110(sambashare) – zamcoot Sep 12 '15 at 13:01
  • 1
    @elnurcoot then `echo $HOME` should say `/home/elnur`, and your `.gitconfig` should be there. No sudo should be required. – VonC Sep 12 '15 at 13:01
  • that is correct but it was not there until i used sudo, that is the thing.. anyway - i will try to config other data without sudo and see if it works :) – zamcoot Sep 12 '15 at 13:04
  • if you use sudo it will create the .gitconfig file in the correct home directory just as sudo echo $HOME will print the correct home directory, the issue is that it will be owned by root and in the root group with rw-r--r-- priviledges – Rolf of Saxony Sep 12 '15 at 13:30
  • @VonC I tried `git config --global` and gave a `git config --global alias.aa="add --all"` but the .config file do not appear when `ls -alrt`. I am in the /home/user. It it visible when I list them like: `git config --global -l` – lft93ryt Aug 05 '17 at 16:20
  • 2
    @lft93ryt try `git config -l --show-origin`: you will see what config is where. – VonC Aug 05 '17 at 20:44
  • For the ```/etc/gitconfig``` file mystery, run As root ```# git config --list –show-origin``` and the resulting file will be ```/root/.gitconfig```. use ```nano``` to view it. I still wonder why i also got the mystery file too. – ColinWa Jan 05 '18 at 11:33
8

To find your global .gitconfig file:

  1. Open your terminal or command prompt
  2. Go to your root directory by typing cd ~
  3. Once in your root folder type ls -alrt
  4. You will see a .gitconfig file
    • To open your .gitconfig file type open .gitconfig

To find a particular repository's .gitconfig file:

  1. Open your terminal or command prompt
  2. Go to your repository's root directory by typing cd path/to/repository-directory
  3. Once in your repository's root directory type ls -alrt
  4. You will see a .git directory. Type cd .git
  5. Once in your repository's git directory type ls -alrt
  6. You will see a config file
    • To open your repository's .gitconfig file type open config
BinaryJoe01
  • 1,141
  • 10
  • 12
1

I got my config file by using git config --system --list

Blue
  • 22,608
  • 7
  • 62
  • 92
Help Out
  • 11
  • 2
1

Just run the following commands to discover the location of each Git config file:

sudo git -c core.editor=ls\ -al config --system --edit
sudo git -c core.editor=ls\ -al config --global --edit
sudo git -c core.editor=ls\ -al config --local --edit
sudo git -c core.editor=ls\ -al config --worktree --edit

You must be in a Git repo for the last two commands to work. The last command only works if you have multiple Git worktrees enabled.

Here's what it looks like on Ubuntu:

enter image description here

If you try and do git config on global or system you may need elevated rights, as the Git config files might be in the protected \root or \etc directories.

sudo git config --global user.name "cameronmcnz"

enter image description here

Cameron McKenzie
  • 3,684
  • 32
  • 28