In my git workflow we have one main repository and one branch, master. Everyone pulls from remote master and everyone pushes to remote master. I want to work in my own branch while I prepare a feature. So far my history is something like this:
git pull --rebase
git checkout -b new_feature
<make some commits>
git checkout master
git pull --rebase
Now I want to merge the branch and here's what I need:
- No merge commits in my local master branch.
- All commits made into my new_feature branch merged into master as if I had made them in master.
- All merged commits to be merged somewhere on top of my local remote head pointer.
My biggest concern is item 3, when is needed so that I can safely push the changes. If the merged commits are intertwined with commits before head then I will have problems pushing, see related problem I had: git: Pushing Single Commits, Reordering with rebase, Duplicate Commits.
I've read the following:
- http://mettadore.com/2011/05/06/a-simple-git-rebase-workflow-explained/
- Keep commits history after a 'git merge'
- How do you rebase the current branch's changes on top of changes being merged in?
And I think I need to do:
git checkout master
git pull --rebase
git checkout new_feature
git rebase master
git checkout master
git rebase new_feature
git push
My understanding is that
git checkout new_feature
git rebase master
will make new_feature appear as if it was branched off from the new current head. Is that true? And that
git checkout master
git rebase new_feature
will place new_feature on top of master. Is that correct? If so, this is the main point of my confusion. If "git rebase master" places master commits at the bottom of new_feature, then why does "git rebase new_feature" place new_feature commits at the top of master, i.e. why doesn't it do the opposite?