I'm working on a web project on the local branch, dev
, and I currently complete my part. But here is the thing, my local branch is behind the remote branch main
. Generally, I'd like to use git merge
to merge remote branch. But this time, my manager ask me use rebase
to merge, and I never rebase
to merge remote branch. So, here I'm seeking help about the process that use rebase
to merge when local branch behind remote branch.
CodePudding user response:
- First fetch all remote branches:
git fetch
- Then rebase your branch onto the remote main:
git rebase main dev
- If there are conflicts, resolve them,
git add
,git rebase --continue
- (Force-) push your updated branch:
git push origin dev
orgit push origin dev
Alternatively, with git pull:
- Switch to branch
git checkout dev
git pull --rebase origin main
- Push
Personally, I always prefer fetch local operations, because it allows me to verify the remote history, before creating new commits.