DEV Community

Discussion on: Tiny Tips : git pull --rebase

Collapse
 
zeffk profile image
Huzaif Qazi • Edited

Hello have doubt regarding git rebase .

I have two branches one main and another my feature branch .

I made 3 commit on feature branch at 1pm 2pm and 3pm respectively, now I did the 4th commit on main-dev at 4pm , When I am on feature branch and running git rebase main-dev , on top of 4th commit my 3 commits are there absolutely as expected , but here comes the problem as soon as I am running git push my feature branch is getting diverged and then getting merged into feature again .

Can you help here , why it is happening.

Below screenshot for reference

Image description

Collapse
 
tandrieu profile image
Thibaut Andrieu

Hi,

That's unexpected, indeed. Do you use command line or a GUI FrontEnd like SourceTree or GitKraken ? GUI Frontend tends to do some extra stuff behind the scene.

You can try to do it fully by hand:

git fetch  # retrieve server modifications
git checkout feature/cart-page  # ensure you are in your feature branch
git rebase origin/main # rebase current branch onto origin/main branch
Enter fullscreen mode Exit fullscreen mode

Ensure your tree is as expected (with gitk or any gui tool), and then

git push origin feature/cart-page:feature/cart-page
Enter fullscreen mode Exit fullscreen mode

Now you should have the expected behavior.

Hope this help 😊

Note: "git pull --rebase" is a shortcut for "git fetch; git rebase origin/main"

Collapse
 
zeffk profile image
Huzaif Qazi

Thanks , adding --force while pushing after doing rebase helped me in getting expected result.