Skip to main content

A guide on configuring Git

· 6 min read
유기한
Principal Engineer @ Samsung

git

Git에서 git config 명령어를 사용하면 사용자 정보, 에디터, diff 도구, alias(별칭) 등 다양한 설정을 조정할 수 있습니다.

다음은 Git에서 사용 가능한 모든 git config 명령어 리스트입니다.

1. 기본 사용자 정보 설정

git config --global user.name "사용자이름"     # 사용자 이름 설정
git config --global user.email "이메일주소" # 사용자 이메일 설정
  • --global: 전체 시스템에서 적용 (현재 사용자)
  • --local: 현재 저장소에서만 적용 (.git/config)
  • --system: 시스템 전체 적용 (/etc/gitconfig)

2. Git 에디터 설정

git config --global core.editor "vim"           # 기본 에디터를 Vim으로 설정
git config --global core.editor "code --wait" # 기본 에디터를 VS Code로 설정
git config --global core.editor "open -a 'IntelliJ IDEA' --args --wait" # 기본 에디터를 IntelliJ로 설정

3. Diff & Merge 도구 설정

1) Visual Studio Code

git config --global diff.tool vscode
git config --global difftool.vscode.cmd "code --wait --merge $LOCAL $REMOTE $BASE $MERGED" # 3-way diff

git config --global merge.tool vscode
git config --global mergetool.prompt false
git config --global mergetool.vscode.cmd "code --wait --merge $LOCAL $REMOTE $BASE $MERGED" # 3-way merge

2) IntelliJ-IDEA

git config --global diff.tool intellij
git config --global difftool.intellij.cmd "idea diff $LOCAL $REMOTE"

git config --global merge.tool intellij
git config --global mergetool.prompt false
git config --global mergetool.intellij.cmd "idea merge $LOCAL $REMOTE $BASE $MERGED"

4. 자동 줄바꿈(Line Ending) 설정

git config --global core.autocrlf true  # Windows에서 자동 줄바꿈 변환
git config --global core.autocrlf input # macOS/Linux에서는 input 사용
  • Windows: true (CRLF → LF 변환)
  • macOS/Linux: input (LF 유지)

5. 색상 출력 설정

git config --global color.ui auto      # 자동 색상 출력 활성화
git config --global color.branch auto # 브랜치 색상 설정
git config --global color.diff auto # diff 색상 설정
git config --global color.status auto # 상태 색상 설정

6. Credential (인증 정보) 저장 설정

git config --global credential.helper cache       # 인증 정보 캐시 저장
git config --global credential.helper store # 영구 저장 (보안 취약 주의)
git config --global credential.helper "manager-core" # Windows 인증 관리자 사용
  • cache: 일정 시간 동안 인증 정보 저장
  • store: 인증 정보를 파일에 영구 저장 (주의!)

7. Alias(별칭) 설정

git config --global alias.st status    # `git st` → `git status`
git config --global alias.co checkout # `git co` → `git checkout`
git config --global alias.br branch # `git br` → `git branch`
git config --global alias.ci commit # `git ci` → `git commit`
git config --global alias.df diff # `git df` → `git diff`
git config --global alias.last "log -1 HEAD" # `git last` → 마지막 커밋 로그 확인
  • git st, git co 등의 짧은 명령어로 Git 사용 가능!

8. Push 관련 설정

git config --global push.default simple  # 기본 push 동작 (현재 브랜치만 푸시)
git config --global push.autoSetupRemote true # `git push -u` 없이 자동으로 upstream 설정
  • simple: 현재 브랜치만 푸시 (권장)
  • matching: 모든 브랜치를 원격과 동기화 (비추천)

9. Fetch & Pull 설정

git config --global pull.rebase true  # pull 시 rebase 사용 (충돌 최소화)
git config --global fetch.prune true # 원격에서 삭제된 브랜치를 자동 정리

10. Rebase & Merge 설정

git config --global rebase.autoStash true  # rebase 전 자동 stash
git config --global merge.ff only # fast-forward merge만 허용

11. Git 로그 설정

git config --global log.decorate full  # 로그에 브랜치 및 태그 정보 표시
git config --global log.date iso # 날짜를 ISO 형식으로 표시

12. Git Hooks 관련 설정

git config --global core.hooksPath ~/.githooks  # Git hooks의 기본 경로 설정

13. Git 서명(GPG) 설정

git config --global commit.gpgSign true         # 모든 커밋에 GPG 서명 추가
git config --global user.signingkey YOUR_KEY_ID # 서명에 사용할 GPG 키 설정

14. Safe Directory 설정 (권한 문제 해결)

git config --global --add safe.directory /path/to/repo
  • fatal: detected dubious ownership in repository 오류 해결!

15. Git 기본 브랜치 이름 변경

git config --global init.defaultBranch main  # 새 저장소의 기본 브랜치를 `main`으로 설정
  • 기존 master 대신 main을 기본 브랜치로 설정

16. 설정 값 확인 및 삭제

git config --global --list  # 설정된 모든 값 확인
git config --global user.name # 특정 설정 확인
git config --global --unset user.name # 특정 설정 삭제

📌 정리

카테고리주요 명령어
기본 설정user.name, user.email
에디터 설정core.editor
Diff & Mergediff.tool, merge.tool
자동 줄바꿈core.autocrlf
색상 설정color.ui
인증 정보 저장credential.helper
Alias 설정alias.st, alias.co
Push 설정push.default, push.autoSetupRemote
Fetch & Pullpull.rebase, fetch.prune
Rebase & Mergerebase.autoStash, merge.ff
로그 설정log.decorate, log.date
Git Hookscore.hooksPath
GPG 서명commit.gpgSign, user.signingkey
Safe Directorysafe.directory
기본 브랜치init.defaultBranch
설정 확인/삭제git config --list, git config --unset

이제 git config 명령어를 자유롭게 활용할 수 있습니다!

감사합니다.