2

I managed somehow to make Git running with Github and now (a year later) I would like to teach the group how they can do the same. I learned quite a lot from here, but even with the answer, some things remain unclear. Please apologize, if I didn't got it from the git reference

Questions:

  • Is there a best practice, which parameters should show up in which config file?

... Continued from my example below:

  • I marked the parts which I can access via --system, --global and --local. Does anybody know where the first part belongs to?
  • Green is everything, where I think, it is ok (with my very limited knowledge).
  • Red is strange as it exists twice

When I run git config --list --show-origin I get the following result:

enter image description here

Edit @Code-Apprentice:
From git-bash

$ git config --list --show-origin --system
file:"C:\\Git\\mingw64/etc/gitconfig"   credential.helper=manager

and cmd

>git config --list --show-origin --system
file:"C:\\Git\\mingw64/etc/gitconfig"   credential.helper=manager

Git output as code:

file:"C:\\ProgramData/Git/config"       core.symlinks=false # ... see .git/config 
file:"C:\\ProgramData/Git/config"       core.autocrlf=true
file:"C:\\ProgramData/Git/config"       core.fscache=true
file:"C:\\ProgramData/Git/config"       color.diff=auto
file:"C:\\ProgramData/Git/config"       color.status=auto
file:"C:\\ProgramData/Git/config"       color.branch=auto
file:"C:\\ProgramData/Git/config"       color.interactive=true
file:"C:\\ProgramData/Git/config"       help.format=html
file:"C:\\ProgramData/Git/config"       http.sslcainfo=C:/Git/mingw64/ssl/certs/ca-bundle.crt
file:"C:\\ProgramData/Git/config"       diff.astextplain.textconv=astextplain
file:"C:\\ProgramData/Git/config"       rebase.autosquash=true

file:"C:\\Git\\mingw64/etc/gitconfig"   credential.helper=manager # ... see file:C:/Users/myname/.gitconfig

file:C:/Users/myname/.gitconfig    filter.lfs.clean=git-lfs clean %f
file:C:/Users/myname/.gitconfig    filter.lfs.smudge=git-lfs smudge %f
file:C:/Users/myname/.gitconfig    filter.lfs.required=true
file:C:/Users/myname/.gitconfig    user.name=My name
file:C:/Users/myname/.gitconfig    user.email=my.name@domain.com
file:C:/Users/myname/.gitconfig    credential.helper=wincred
file:C:/Users/myname/.gitconfig    alias.hist=log --pretty=format:'%h - %an, %ad: %s' --graph --date=short
file:C:/Users/myname/.gitconfig    difftool.kdiff3.cmd='C:/Program Files/KDiff3/kdiff3' $LOCAL $REMOTE
file:C:/Users/myname/.gitconfig    difftool.kdiff3.keepbackup=false
file:C:/Users/myname/.gitconfig    difftool.kdiff3.trustexitcode=false
file:C:/Users/myname/.gitconfig    merge.conflictstyle=diff3

file:.git/config        core.repositoryformatversion=0
file:.git/config        core.filemode=false
file:.git/config        core.bare=false
file:.git/config        core.logallrefupdates=true
file:.git/config        core.symlinks=false
file:.git/config        core.ignorecase=true
file:.git/config        core.hidedotfiles=dotGitOnly
file:.git/config        remote.origin.url=https://github.com/repo/Rettung-ZCH
file:.git/config        remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
file:.git/config        branch.master.remote=origin
file:.git/config        branch.master.merge=refs/heads/master
file:.git/config        branch.dev1.remote=origin
file:.git/config        branch.dev1.merge=refs/heads/dev1
file:.git/config        branch.dev2.remote=origin
file:.git/config        branch.dev2.merge=refs/heads/dev2
Christoph
  • 6,841
  • 4
  • 37
  • 89

3 Answers3

4
  • Is there a best practice, which parameters should show up in which config file?

This is totally up to you, whether you want a setting only on one repository, on all repositories you access with your user account or on all repositories on this machine (each time of course only if not overwritten from a lower config level).

  • I marked the parts which I can access via --system, --global and --local. Does anybody know where the first part belongs to?

As far as I remember these are the default values of the Git for Windows client and are on (or rather above) the system settings level. You can list and change them with git config --file c:\ProgramData\Git\config --list and so on.

  • Green is everything, where I think, it is ok (with my very limited knowledge).

As I said, totally up to you. The local green settings are most probably only useful on the local level, yes. For me user.email for example is not set on global level on my work box, as I work on private and corporate repos and use different addresses there. By not configuring either on the global level I am reminded on local level to set it when doing the first commit.

  • Red is strange as it exists twice

You can have each setting on each level, lower level overwriting value of upper levels, this is perfectly legal. You can e. g. set for all users on the system to use credential.helper=manager but for your user to use credential.helper=wincred like you have it in your example.

Vampire
  • 35,631
  • 4
  • 76
  • 102
  • Really clear answer! I just don't understand the last sentence: "all users on the system" means "my laptop" and "your user" means "the one who is logged in my laptop"? As I am the only one working one the laptop, the two are the same? – Christoph Mar 09 '17 at 07:00
  • If you are the only one logging into the box and you always use the same useraccount, they are effectively the same, yes. – Vampire Mar 09 '17 at 07:52
  • Last (off-topic) question: Could you tell from the config file, whether I use the credential helper -manager or wincred or an ssh-key? As said, at some point a year ago everything worked, but I don't really have a clue what was going on ;-) – Christoph Mar 09 '17 at 10:08
  • Sure, you are using wincred if credentials are needed. But if you use an SSH URL, the ssh-key is used. – Vampire Mar 09 '17 at 10:19
2

For Windows there should be following global settings:

rem always have Linux line endings in text files
git config --global core.autocrlf input
rem support more than 260 characters on Windows
rem See https://stackoverflow.com/a/22575737/873282 for details
git config --global core.longpaths true
rem some color and diff tweaks
rem   Use SVN's ||| also in git
rem   See https://git-scm.com/docs/git-config#Documentation/git-config.txt-mergeconflictStyle for details
git config --global merge.configStyle "diff3"
git config --global color.diff.new "green bold"
git config --global color.status.updated "green bold"
git config --global color.branch.current "green bold"
rem Sort branches at "git branch -v" by committer date
git config --global branch.sort -committerdate

(The hints at https://stackoverflow.com/a/24045966/873282 are obsolete)

koppor
  • 19,079
  • 15
  • 119
  • 161
  • Some comments / questions. 1) `git config --global core.autocrlf input`: This mean that nothing ever gets changed? If all my colleagues (also) work on windows, everything is fine; but if Windows AND Linux were used simultaneaously, one (either Windows or Linux) had to change? 2) `git config --global core.longpaths true` good point, I changed that. 3) I guess, the `diff`, `color` and `branch.sort` seetings are more a matter of taste? Thanks for clarification :-) – Christoph Mar 24 '20 at 10:37
1

Git will override more global settings with more local ones. The duplicated (red) ones in your output guarantee consistency at a more local level if the more global value is ever changed.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • Ok, part of it is understood. Sorry, I am quite new: What is the part in `/ProgrammData`? Does the file "make sense" to you? Do you have any suggestions for improvements? – Christoph Mar 08 '17 at 16:58
  • @Christoph I think `C:\\ProgramData/Git/config` is the most global file. Essentially this is all the default settings. All of these can be overridden at each lower level. – Code-Apprentice Mar 08 '17 at 21:02
  • @Christoph After taking a closer look, I think that both `C:\\ProgramData/Git/config` and `C:\\Git\\mingw64/etc/gitconfig` are system level settings. The difference is that the first one is for Windows and the second is for Git Bash. I'm willing to bet if you run the same `git config` command from `cmd`, you will not see the `mingw64` config file. – Code-Apprentice Mar 08 '17 at 21:05
  • No, I dont think so. I tested both (See my edit of the question). It seems you have to access them as described in the answer below. – Christoph Mar 09 '17 at 06:50