C.W.K.
Stream
Lesson 03 of 05 · published

push, upstream, push rejection

~18 min · push, upstream

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

push 는 업로드, push rejection 은 history 보호

git push origin feature/x 는 local branch feature/x 의 commit 을 remote 의 feature/x 로 업로드. 새 branch 첫 push 엔 tracking 설정용 -u: git push -u origin feature/x. 그 후엔 feature/x 에서 plain git push 가 default 로 맞는 곳으로. Tracking 이 branch 를 양방향으로 흐르는 한 줄 effort 로 만들어.

Push rejection 은 서버엔 있고 local 엔 없는 history 를 덮어쓰지 않으려는 Git 의 거부야. 에러 메시지가 명확: "Updates were rejected because the remote contains work that you do not have locally." 네 일은 거부 우회가 아니라 remote 작업 먼저 통합. git fetch, 그 다음 새 tip 위에 rebase (git rebase origin/feature/x) 또는 merge (git merge origin/feature/x), 다시 push.

Force push 는 가볍게 잡지 말아야 할 비상구야. git push --force 는 commit 잃을지언정 remote branch 를 local history 로 덮어써. 재앙 버전: 다른 사람이 네가 안 받은 작업 push 했는데 force-push 가 그 commit 들을 서버에서 지움. 더 안전한 — 시니어가 쓸 유일한 — 대안은 git push --force-with-lease, 마지막 fetch 이후 remote tip 이 움직였으면 push 거부. 평소엔 똑같고, 위험할 땐 거부.

Muscle memory 로 박아둘 패턴 둘. 첫 push 에 tracking 설정: git push -u origin <branch>. 안전망 있는 rebase force-push: git push --force-with-lease. git config --global push.default current 설정하면 인자 없는 git push 가 항상 현재 branch 를 추적된 remote 로 push — 우발 wrong-branch push 한 부류 제거.

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) 로 local history 가 remote 와 발산되게. 먼저 plain git push 로 push 해서 거부 메시지 읽어. 그 다음 git push --force-with-lease 로 성공 확인. 거부가 사용한 정확한 문구 + plain --force 였으면 어떻게 됐을지 적어.

Progress

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

댓글 0

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

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