[GitHub 100일 챌린지] Day 23 - Git 초기 설정하기
[GitHub 100일 챌린지] Day 23 - Git 초기 설정하기
100일 챌린지 Day 23 - Git 사용 전 필수 설정을 완료합니다
배울 내용
- 사용자 정보 설정 (필수)
- 기본 설정 최적화
- 설정 확인 및 수정
Topic1. 사용자 정보 설정
Git 커밋에 들어갈 이름과 이메일을 설정합니다.
이름과 이메일 설정 (필수)
해보기:
1
2
3
4
5
# 이름 설정
git config --global user.name "Your Name"
# 이메일 설정
git config --global user.email "your.email@example.com"
실제 예시:
1
2
git config --global user.name "홍길동"
git config --global user.email "hong@example.com"
중요:
1
2
3
4
5
⚠️ 이메일은 GitHub 계정 이메일과 동일하게!
→ 커밋이 GitHub 프로필에 연결됨
⚠️ 설정 안 하면:
→ 커밋할 때마다 오류 발생
설정 확인
해보기:
1
2
3
4
5
6
7
8
# 이름 확인
git config user.name
# 이메일 확인
git config user.email
# 전체 설정 보기
git config --list
출력 예시:
1
2
3
4
user.name=홍길동
user.email=hong@example.com
core.autocrlf=true
...
설정 레벨
3가지 레벨:
1
2
3
4
5
6
7
8
# 1. System (모든 사용자)
git config --system
# 2. Global (현재 사용자) ← 주로 사용
git config --global
# 3. Local (현재 Repository만)
git config --local
우선순위:
1
Local > Global > System
결과: Git 커밋에 사용될 사용자 정보가 설정됩니다
Topic2. 기본 설정 최적화
편리한 Git 사용을 위한 추가 설정입니다.
기본 브랜치 이름
해보기:
1
2
# main으로 설정 (권장)
git config --global init.defaultBranch main
이유:
1
2
3
✅ GitHub 기본값과 일치
✅ 최신 표준
❌ master는 구식
에디터 설정
VS Code:
1
git config --global core.editor "code --wait"
Vim (기본):
1
git config --global core.editor "vim"
Nano (간단):
1
git config --global core.editor "nano"
줄바꿈 설정
Windows:
1
git config --global core.autocrlf true
Mac/Linux:
1
git config --global core.autocrlf input
설명:
1
2
Windows: CRLF ↔ LF 자동 변환
Mac/Linux: LF 유지
컬러 출력
해보기:
1
git config --global color.ui auto
효과:
1
2
3
4
Git 출력에 컬러 추가:
🟢 추가된 파일
🔴 삭제된 파일
🟡 수정된 파일
Credential Helper
해보기:
1
2
3
4
5
6
7
8
# Windows
git config --global credential.helper wincred
# Mac
git config --global credential.helper osxkeychain
# Linux
git config --global credential.helper store
효과:
1
2
✅ GitHub 로그인 정보 저장
✅ 매번 입력 불필요
단축키 (Alias)
자주 쓰는 명령어 단축:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# status → st
git config --global alias.st status
# checkout → co
git config --global alias.co checkout
# commit → ci
git config --global alias.ci commit
# branch → br
git config --global alias.br branch
# log 예쁘게
git config --global alias.lg "log --oneline --graph --all"
사용 예:
1
2
3
4
5
# 기존
git status
# 단축키
git st
해보기: 필수 설정하기
1
2
3
4
5
6
7
8
9
10
11
# 1. 기본 브랜치
git config --global init.defaultBranch main
# 2. 컬러 출력
git config --global color.ui auto
# 3. Credential helper (OS에 맞게)
git config --global credential.helper wincred
# 4. 에디터 (선택)
git config --global core.editor "code --wait"
결과: Git을 더 편리하게 사용할 수 있는 환경이 구성됩니다
Topic3. 설정 확인 및 수정
설정을 확인하고 필요시 수정하는 방법입니다.
설정 확인
전체 설정 보기:
1
git config --list
특정 설정 확인:
1
2
3
git config user.name
git config user.email
git config init.defaultBranch
설정 파일 위치:
1
2
3
4
5
# Global 설정 파일 보기
cat ~/.gitconfig
# 또는
git config --global --edit
설정 파일 예시 (~/.gitconfig):
1
2
3
4
5
6
7
8
9
10
[user]
name = 홍길동
email = hong@example.com
[init]
defaultBranch = main
[color]
ui = auto
[alias]
st = status
co = checkout
설정 수정
명령어로 수정:
1
2
3
4
5
# 이름 변경
git config --global user.name "새로운 이름"
# 이메일 변경
git config --global user.email "new@example.com"
에디터로 수정:
1
git config --global --edit
특정 설정 삭제:
1
2
git config --global --unset user.name
git config --global --unset alias.st
전체 초기화 (주의!):
1
2
3
4
5
# Global 설정 파일 삭제
rm ~/.gitconfig
# 또는 백업 후 삭제
mv ~/.gitconfig ~/.gitconfig.backup
Repository별 설정
Local 설정 (현재 Repository만):
1
2
3
4
5
6
7
8
9
# Repository 폴더로 이동
cd my-project
# Local 설정
git config --local user.name "프로젝트용 이름"
git config --local user.email "project@example.com"
# 확인
git config --local --list
사용 예:
1
2
회사 프로젝트: 회사 이메일
개인 프로젝트: 개인 이메일
설정 우선순위 확인
해보기:
1
2
3
4
5
6
# 실제 사용될 값 확인
git config user.name
git config user.email
# 어느 레벨의 설정인지 확인
git config --show-origin user.name
출력 예시:
1
file:/home/user/.gitconfig 홍길동
필수 설정 체크리스트
해보기:
1
2
3
4
5
6
7
8
9
10
11
# 1. 이름 확인
git config user.name
# 2. 이메일 확인
git config user.email
# 3. 기본 브랜치 확인
git config init.defaultBranch
# 4. 전체 설정 확인
git config --list
결과: 올바른 Git 설정이 완료되고 확인됩니다
정리
완료 체크:
- user.name을 설정했다
- user.email을 설정했다 (GitHub와 동일)
- 기본 설정을 최적화했다
필수 설정:
1
2
3
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
git config --global init.defaultBranch main
권장 설정:
1
2
3
git config --global color.ui auto
git config --global credential.helper (OS별)
git config --global alias.st status
설정 확인:
1
2
3
git config --list
git config user.name
git config user.email
다음: Day 24 - 로컬 저장소 초기화 →
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.
