umar
umar

Reputation: 4389

how to use git rebase more effectively in the following scenario

My workflow is as follows: there is a main branch called develop, which should always have passing tests. When working on a feature, I create a new branch to work on this ticket with:

git checkout -b feature_name

Then create a remote tracking branch for it with:

git push -u origin feature_name

Then I keep committing on this branch, and sometimes I merge from develop with this:

git checkout develop; git pull; git checkout feature_branch; git merge develop

so that the branch keeps getting updated from the develop branch.

When I am done, I merge this branch into develop and push:

git checkout develop; git pull; git merge feature_branch; git push

This uses the git pull strategy for merging. But when I do the above, sometimes my commits show on top, sometimes somewhere else, sometimes interspersed, so it is hard to see what I did. I want to know how to use rebase in the above scanario so that the history of my commits shows on top.

Upvotes: 0

Views: 144

Answers (2)

Vili
Vili

Reputation: 1679

In the third line change your workflow to

git rebase origin/develop

and at the end

git checkout develop; git pull; git rebase feature_branch; git push;

A note: rebase will only work without problems if you don't rebase remote commits. You don't want to change remote history, do you?

Upvotes: 1

Amber
Amber

Reputation: 526533

Just change git merge develop to git rebase develop.

Upvotes: 1

Related Questions