초기 설정
한 줄 요약
Git 사용 전 필수로 설정해야 하는 사용자 정보와 기본 옵션
선행 지식
- Git 설치 - Git이 설치되어 있어야 합니다
필수 설정: 사용자 정보
Git은 모든 Commit에 누가 변경했는지 기록합니다. 따라서 사용자 정보 설정은 필수입니다.
git config --global user.name "홍길동"
git config --global user.email "hong@example.com"주의
- GitHub를 사용한다면 GitHub 계정과 동일한 이메일을 사용하세요
- 이메일이 다르면 GitHub에서 잔디(contribution)가 심어지지 않습니다
설정 확인
# 전체 설정 보기
git config --list
# 특정 설정 보기
git config user.name
git config user.email권장 설정
기본 브랜치 이름
Git의 기본 브랜치 이름을 main으로 설정합니다 (GitHub 표준):
git config --global init.defaultBranch main기본 에디터
commit 메시지 작성 시 사용할 에디터를 설정합니다:
# VS Code
git config --global core.editor "code --wait"
# Vim
git config --global core.editor "vim"
# nano
git config --global core.editor "nano"줄바꿈 처리
운영체제마다 줄바꿈 문자가 다릅니다. 협업 시 문제를 방지하려면:
# Windows
git config --global core.autocrlf true
# macOS / Linux
git config --global core.autocrlf input한글 파일명 처리
한글 파일명이 깨지지 않도록 설정:
git config --global core.quotepath false설정 범위
git config 명령어는 세 가지 범위로 설정할 수 있습니다:
| 옵션 | 범위 | 설정 파일 위치 |
|---|---|---|
--system | 시스템 전체 | /etc/gitconfig |
--global | 현재 사용자 | ~/.gitconfig |
--local | 현재 저장소 | .git/config |
우선순위: local > global > system
# 회사 프로젝트에서만 다른 이메일 사용하기
cd 회사프로젝트
git config --local user.email "hong@company.com"설정 파일 직접 편집
설정 파일을 직접 편집할 수도 있습니다:
# 에디터로 전역 설정 파일 열기
git config --global --edit설정 파일 내용 예시 (~/.gitconfig):
[user]
name = 홍길동
email = hong@example.com
[init]
defaultBranch = main
[core]
editor = code --wait
quotepath = false
autocrlf = input전체 권장 설정 (복사용)
macOS/Linux용:
# 필수 설정
git config --global user.name "이름"
git config --global user.email "이메일"
# 권장 설정
git config --global init.defaultBranch main
git config --global core.editor "code --wait"
git config --global core.autocrlf input
git config --global core.quotepath falseWindows용:
# 필수 설정
git config --global user.name "이름"
git config --global user.email "이메일"
# 권장 설정
git config --global init.defaultBranch main
git config --global core.editor "code --wait"
git config --global core.autocrlf true
git config --global core.quotepath false자주 하는 실수
”Author identity unknown” 에러
*** Please tell me who you are.
원인: 사용자 정보를 설정하지 않음
해결:
git config --global user.name "이름"
git config --global user.email "이메일"GitHub 잔디가 안 심어질 때
원인: Git 설정 이메일과 GitHub 계정 이메일이 다름
해결:
- GitHub 설정에서 등록된 이메일 확인
- 동일한 이메일로 Git 설정
git config --global user.email "github계정이메일@example.com"다음 단계
초기 설정이 완료되었습니다! 이제 Git의 핵심 개념을 배워봅시다:
또는 바로 첫 저장소를 만들어보세요:
→ git init