Git config 설정
git에 대한 환경 설정은 git config를 사용해서 할 수 있다.
대부분의 site 들에서 "~/.gitconfig에 설정하면된다" 라는 식의 어찌보면 매우 부정확한 방법을 가이드 하고 있기에 바로잡고자 한다.
설정을 위한 방법은 3가지가 제공된다.
1. SYSTEM : /etc/gitconfig를 사용하는 방법
시스템을 사용하는 모든 사용자와 모든 저장소에 적용되는 방법이다.
git config --system 옵션을 사용한다.
2. GLOBAL : ~/.gitconfig 혹은 ~/.config/git/config를 사용하는 방법
특정 사용자 (아마도 현재 사용자) 에게만 적용된느 설정이다.
git config --global 옵션을 사용한다.
3. LOCAL : .git/config를 사용하는 방법
현재 GIt 디렉토리, 특정 저장소에만 적용된다.
git config --local 옵션을 사용한다.
또한 각 설정은 모두 역순으로 우선시 된다. (3 -> 2 -> 1의 순서이다.)
system에 설정하면 다음과 같이 user.name이 나오는 것을 확인할 수 있다.
$ git config --list
$ sudo git config --system user.name "system_haheho"
$ git config --list
user.name=system_haheho
global을 설정하면 global이 다음에 나오기 때문에 system보다 우선하게 설정되는 것을 확인할 수 있다.
$ git config --global user.name "global_haheho"
$ git config --list
user.name=system_haheho
user.name=global_haheho
local의 경우 git 디렉토리 에서만 가능하기 때문에 예제를 위해서 sample git을 clone 한 후에 테스트 하였다.
맨 아래줄에 local_haheho로 설정되는것을 확인할 수 있다.
$ git clone https://github.com/githubtraining/hellogitworld.git
Cloning into 'hellogitworld'...
remote: Enumerating objects: 306, done.
remote: Total 306 (delta 0), reused 0 (delta 0), pack-reused 306
Receiving objects: 100% (306/306), 95.82 KiB | 5.99 MiB/s, done.
Resolving deltas: 100% (69/69), done.
$ cd hellogitworld/
$ git config --local user.name "local_haheho"
$ git config --list
user.name=system_haheho
user.name=global_haheho
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/githubtraining/hellogitworld.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
user.name=local_haheho
local의 경우 '--local' 옵션을 설정하지 않아도 default option이라는 것을 확인할 수 있다.
user.name이 "local_haheho"에서 "default_haheho"로 변경된 것을 확인할 수 있다.
$ git config user.name "default_local_haheho"
$ git config --list
user.name=system_haheho
user.name=global_haheho
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/githubtraining/hellogitworld.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
user.name=default_local_haheho
참고 : https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup