본문 바로가기
C.W.K.
Stream
Lesson 03 of 05 · published

push, upstream, push rejection

~18 min · push, upstream

Level 0추적 전 새싹
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

push는 업로드고, push rejection은 이력 보호야

git push origin feature/x는 로컬 feature/x의 commit을 remote의 feature/x로 올려. 새 branch를 처음 push할 때는 tracking을 설정하는 -u를 붙여 git push -u origin feature/x를 써. 이후에는 feature/x에서 plain git push만 실행해도 알맞은 곳으로 향해. Tracking이 오가는 일을 한 줄짜리 습관으로 만들어주는 거야.

Push rejection은 서버에는 있지만 로컬에는 없는 이력을 덮지 않으려는 Git의 보호 장치야. 메시지도 분명해. "Updates were rejected because the remote contains work that you do not have locally." 할 일은 거부를 우회하는 게 아니라 remote 작업을 먼저 통합하는 거야. git fetch한 뒤 새 tip 위로 git rebase origin/feature/x하거나 git merge origin/feature/x하고 다시 push해.

Force push는 가볍게 쓸 명령이 아니야. git push --force는 commit 손실을 무릅쓰고 remote branch를 로컬 이력으로 덮어써. 다른 사람이 네가 아직 받지 않은 작업을 push했다면 그 commit을 서버에서 지울 수도 있어. 더 안전한 대안은 git push --force-with-lease야. 마지막 fetch 뒤 remote tip이 움직였다면 push를 거부해. 평소 편의는 같고 위험한 순간에만 멈춰.

두 pattern을 손에 익혀. 첫 push에서 tracking 설정: git push -u origin <branch>. rebase 뒤 안전장치를 둔 force-push: git push --force-with-lease. git config --global push.default current를 설정하면 인자 없는 git push가 현재 branch를 tracked remote로 보내 잘못된 branch를 밀어 올리는 실수를 줄여.

Code

첫 push + 일상 push·bash
# 새 branch 첫 push — tracking 설정:
git push -u origin feature/profile-page

# tracking 설정 후엔:
git push

# 실제 push 없이 push 할 거 미리 보기:
git push --dry-run

# 다른 remote 로 push (fork+upstream 세팅):
git push fork feature/profile-page

# remote branch 삭제:
git push origin --delete feature/profile-page
Rebase 후 안전한 force-push·bash
# 이미 push 된 commit 을 rewrite 한 local rebase 후:
git push --force-with-lease

# --force-with-lease 가 체크하는 것:
#   마지막 fetch 이후 origin/<branch> 가 움직였으면 거부
#   — 동시에 누군가 push 했다는 뜻.

# 위험 — 그 branch 를 너만 쓴다고 확신할 때만:
git push --force          # remote history 무조건 덮어씀

# 안전한 push default 설정:
git config --global push.default current
git config --global push.followTags true

External links

Exercise

새 branch를 만들어 commit 두 개를 쌓고 git push -u해. main에 대해 git rebase하거나 마지막 commit을 amend해 로컬 이력을 remote와 발산시켜. 먼저 plain git push를 실행해 거부 message를 읽고, 이어서 git push --force-with-lease가 성공하는지 확인해. 거부의 정확한 문구와 plain --force였다면 어떤 일이 벌어졌을지 적어봐.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.