[GitHub 100일 챌린지] Day 35 - Push/Pull 트러블슈팅
100일 챌린지 Day 35 - 자주 발생하는 push/pull 에러를 해결합니다
배울 내용
- rejected 에러 해결
- 충돌 해결 실전
- 네트워크 문제 해결
Topic1. rejected 에러 해결
push rejected = Remote가 최신이 아님
가장 흔한 에러를 해결하는 방법입니다.
에러 메시지
1
2
3
4
5
git push origin main
# 에러:
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'origin'
의미:
1
2
Remote에 내가 모르는 커밋이 있음
먼저 pull 받아서 합쳐야 함
해결 방법 1: Pull 먼저
1
2
3
4
5
6
7
8
# 1. Remote 최신 내용 받기
git pull origin main
# 2. 충돌 없으면 자동 merge됨
# 충돌 있으면 해결
# 3. 다시 push
git push origin main
해결 방법 2: Fetch + Rebase
1
2
3
4
5
6
7
8
# 1. Fetch로 안전하게
git fetch origin
# 2. Rebase로 정리
git rebase origin/main
# 3. Push
git push origin main
해결 방법 3: Force Push (위험!)
main에서 push가 거부되면 앞의 두 방법으로 원격 변경을 먼저 통합합니다. 혼자 쓰는 브랜치에서 이미 올린 커밋을 의도적으로 고친 경우에만 제한적으로 강제 push를 검토합니다. --force-with-lease도 원격 이력을 바꾸므로, 원격의 현재 커밋을 확인하고 대상 브랜치를 명시하세요. git push 공식 문서
⚠️ 언제 force push?:
1
2
3
4
✅ 혼자 작업하는 브랜치
✅ 실수한 커밋 수정 후
❌ 팀 작업 브랜치 (절대 안 됨!)
❌ main/master 브랜치
해보기: Rejected 에러 해결
1
2
3
4
5
6
7
8
9
10
11
12
13
# 시뮬레이션
# 1. Push 시도
git push origin main
# rejected 에러!
# 2. Pull로 해결
git pull origin main
# 자동 merge 또는 충돌 해결
# 3. 다시 Push
git push origin main
# 성공!
결과: Rejected 에러를 성공적으로 해결했습니다
Topic2. 충돌 해결 실전
실제 프로젝트에서 자주 발생하는 충돌 패턴입니다.
충돌 패턴 1: 같은 줄 수정
상황:
1
2
3
4
5
// 내가 수정
const API_URL = 'https://api.mysite.com';
// 팀원이 수정
const API_URL = 'https://api.newsite.com';
충돌 파일:
1
2
3
4
5
<<<<<<< HEAD
const API_URL = 'https://api.mysite.com';
=======
const API_URL = 'https://api.newsite.com';
>>>>>>> origin/main
해결:
1
2
// 팀원과 상의 후 결정
const API_URL = 'https://api.newsite.com';
충돌 패턴 2: 파일 삭제 vs 수정
상황:
1
2
내가: index.html 삭제
팀원: index.html 수정
에러:
1
2
CONFLICT (modify/delete): index.html deleted in HEAD
and modified in origin/main.
해결:
1
2
3
4
5
6
7
8
# 파일 유지하려면
git add index.html
# 파일 삭제하려면
git rm index.html
# 커밋
git commit
충돌 패턴 3: 이진 파일 충돌
상황:
1
2
이미지 파일(.png, .jpg)
양쪽에서 수정
해결:
1
2
3
4
5
6
7
8
9
10
# 내 버전 사용
git checkout --ours image.png
git add image.png
# 또는 Remote 버전 사용
git checkout --theirs image.png
git add image.png
# 커밋
git commit
충돌 해결 도구
VS Code:
1
2
3
4
5
충돌 파일 열면:
[Accept Current Change]
[Accept Incoming Change]
[Accept Both Changes]
버튼 제공
Git GUI 도구:
1
2
3
4
# Git 기본 merge tool
git mergetool
# 설정된 도구 (예: vimdiff) 실행
해보기: 복잡한 충돌 해결
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 1. Pull 시 충돌 발생
git pull origin main
# CONFLICT in multiple files!
# 2. 충돌 파일 확인
git status
# both modified: file1.js
# both modified: file2.js
# both modified: styles.css
# 3. 하나씩 해결
vim file1.js
# 충돌 해결
git add file1.js
vim file2.js
# 충돌 해결
git add file2.js
vim styles.css
# 충돌 해결
git add styles.css
# 4. 커밋
git commit -m "Resolve merge conflicts"
# 5. Push
git push origin main
결과: 여러 파일의 충돌을 체계적으로 해결했습니다
Topic3. 네트워크 문제 해결
인증, 연결, 속도 관련 문제를 해결합니다.
문제 1: 인증 실패
에러:
1
fatal: Authentication failed
해결
HTTPS를 사용한다면 GitHub CLI 또는 Git Credential Manager에서 로그인합니다. GitHub CLI가 설치되어 있다면 아래 URL의 user/repo를 실제 저장소로 바꾸고, 로그인 안내에서 HTTPS와 Git 인증을 선택하세요. 토큰을 URL에 넣으면 저장소 설정과 셸 기록에 남을 수 있습니다. 이미 넣었다면 해당 토큰을 폐기하고 원격 주소를 아래처럼 정리하세요. GitHub 인증 정보 설정 가이드
1
2
3
git remote set-url origin https://github.com/user/repo.git
gh auth login
git ls-remote origin HEAD
마지막 명령이 HEAD 해시를 표시하면 원격을 읽을 수 있습니다. Push에는 해당 브랜치에 대한 쓰기 권한도 필요합니다.
문제 2: 연결 시간 초과
에러:
1
2
fatal: unable to access 'https://github.com/...':
Failed to connect to github.com port 443: Timed out
해결:
1
2
3
4
5
6
7
8
9
10
11
12
# 1. 프록시 확인
git config --global http.proxy
git config --global https.proxy
# 2. 프록시 제거
git config --global --unset http.proxy
git config --global --unset https.proxy
# 3. DNS 변경 (8.8.8.8)
# 4. SSH 사용
git remote set-url origin [email protected]:user/repo.git
문제 3: 대용량 파일 push 실패
에러:
1
remote: error: File large-file.zip is 120 MB; this exceeds GitHub's file size limit of 100 MB
해결:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 방법 1: 파일 제거
git rm --cached large-file.zip
git commit --amend
git push origin main
# 방법 2: Git LFS 사용
git lfs install
git lfs track "*.zip"
git add .gitattributes
git add large-file.zip
git commit -m "Use LFS for large files"
git push origin main
# 방법 3: .gitignore에 추가
echo "*.zip" >> .gitignore
git rm --cached large-file.zip
git commit -m "Remove large file"
문제 4: 느린 push/pull
원인과 해결:
1
2
3
4
5
6
7
8
9
10
11
# 원인 1: 큰 히스토리
# 해결: Shallow clone
git clone --depth 1 https://github.com/user/repo.git
# 원인 2: 많은 파일
# 해결: 압축
git gc --aggressive
# 원인 3: 네트워크
# 해결: HTTP 버퍼 크기 증가
git config --global http.postBuffer 524288000
해보기: 종합 트러블슈팅
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 체크리스트
# 1. Git 상태 확인
git status
# 2. Remote 연결 확인
git remote -v
git ls-remote origin
# 3. 계정 확인 (GitHub CLI로 인증하는 경우)
gh auth status
# 4. 충돌 확인
git diff
# 5. 로그 확인
git log --oneline -5
# 6. 로컬과 원격에만 있는 커밋 비교
git fetch origin
git log --oneline --left-right HEAD...origin/main
결과: 다양한 문제를 체계적으로 해결할 수 있습니다
정리
완료 체크:
- rejected 에러를 해결할 수 있다
- 다양한 충돌 패턴을 해결할 수 있다
- 네트워크 문제를 해결할 수 있다
핵심 명령어:
1
2
3
4
5
6
7
git pull origin main # rejected 해결
git checkout --ours file # 내 버전 사용
git checkout --theirs file # Remote 버전 사용
git mergetool # merge 도구 실행
git remote set-url origin URL # Remote URL 변경
git config --global http.proxy # 프록시 설정
git lfs track "*.zip" # LFS 사용
에러 해결 순서:
1
2
3
4
5
1. 에러 메시지 읽기
2. git status로 상태 확인
3. 해결 방법 선택
4. 테스트
5. push/pull 재시도
다음: Day 36 - git status 완벽 가이드 →
