0

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.

2 Answers 2

1

Just change git merge develop to git rebase develop.

Sign up to request clarification or add additional context in comments.

Comments

1

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?

3 Comments

I dont use rebase at all, so I dont rebase remote commits!
So, according to your answer, in my workflow, i replace all git-merge commands with git-rebase commands, and thats it?
Make a copy of your project and try these commands without git push. In this case you won't mess up your remote. (I always do this if I am trying out new - maybe destructive - features.) If you rebase, your history will be cleaner as there will be no Merge commits. And if you rebase origin then you don't have to checkout/pull/checkout/merge.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.