Vấn đề: bạn có local commits chưa push.
Teammate đã push lên remote. git pull = git fetch + git merge → tạo merge commit "Merge branch 'main' of github.com/..." không có ý nghĩa.
# git log trông giống:
# * Merge branch 'main' of ... ← không có ý nghĩa
# |\
# | * teammate: feat: add cart
# * | your: feat: add login
# |/
# * old commitFix: dùng git pull --rebase:
git pull --rebase origin main
# = git fetch + git rebase origin/main
# Kết quả: history linear, commits của bạn replay trên topSet làm default:
git config --global pull.rebase true
# Hoặc per-repo:
git config pull.rebase trueTrường hợp pull --rebase gặp conflict:
# Resolve conflict trong file
git add resolved-file.ts
git rebase --continue
# Hoặc abort:
git rebase --abort # về trạng thái trước pullKhi nào dùng git pull (merge) thay vì rebase:
- Branch đã có merge commits quan trọng (merge commit là intentional)
- Long-lived feature branch muốn preserve merge history
Tip: git pull --rebase --autostash tự động stash local changes trước khi rebase, unstash sau.
Problem: you have local unpushed commits.
A teammate has pushed to remote. git pull = git fetch + git merge → creates a "Merge branch 'main' of github.com/..." commit that has no meaning.
# git log looks like:
# * Merge branch 'main' of ... ← meaningless
# |\
# | * teammate: feat: add cart
# * | your: feat: add login
# |/
# * old commitFix: use git pull --rebase:
git pull --rebase origin main
# = git fetch + git rebase origin/main
# Result: linear history, your commits replayed on topSet as default:
git config --global pull.rebase true
# Or per-repo:
git config pull.rebase trueWhen pull --rebase hits a conflict:
# Resolve conflict in file
git add resolved-file.ts
git rebase --continue
# Or abort:
git rebase --abort # return to pre-pull stateWhen to use git pull (merge) instead of rebase:
- Branch has intentional merge commits that should be preserved
- Long-lived feature branch where merge history is meaningful
Tip: git pull --rebase --autostash automatically stashes local changes before rebasing and unstashes them after.