Asara Asara - 1 year ago 117
Git Question

git does not do rebase

I want to rebase my feature branch into dev branch, so I do

git checkout feature
git rebase dev

then I get

Current branch feature is up to date

thats already strange, shouldn't it update the dev and not the feature?


git checkout dev
git log

shows that there is no new commits from the feature added. What am I doing wrong?


Ray Ray
Answer Source

I'm assuming dev is your primary branch.

If you initial branched feature off of dev (or another branch that was at the same commit point as dev HEAD) and no changes have been commited to dev since that branching, when inside feature (as you are by doing the checkout) if you rebase to dev, nothing should happen. HEADcommit of dev is already feature's base commit.

If commits had been made to dev, then the rebase would have rebased feature to the new dev HEAD.

You don't want to rebase dev, you rebase your feature branch if needed (if dev having changed while working on your feature), then merge the rebased feature branch back into dev.

Here's my flow assuming dev is my primary branch:

git checkout dev
git checkout -b feature

Now I'm in my feature branch. I Made some changes to feature branch commit them, maybe dev has changed in meantime. Still on feature branch, so changing back to dev to look for any changes

git checkout dev
git pull origin dev

So changes happened on dev, so I want to rebase my feature branch

git checkout feature
git rebase dev

Now I'm ready to merge my feature branch back into dev

git checkout dev
git merge --squash feature

Squash is optional, but it condenses changes in the feature branch into a single commit on merging back to dev.

Finally, push the new dev back up for others to enjoy

git push origin dev
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download