Aaron Brewer
Aaron Brewer

Reputation: 3667

Git Rebasing Branch Commits, When It Already Has Separate Merged Branch Commits In It?

Typically my Git work flow is like so:

git add --all
git commit
git push -u origin branch/name
git merge master

From here I make more changes, and repeat the above.

When I am looking at my commit history for the branch, I have commit messages not only for my branch, but also from the merge via master. I want to be able to rebase and squash commits for just my branch. So the last 10 commits would be my branch specific commits, and without all other commits from a merge into my branch. I wouldn't mind if Git gave me a commit for a merge from another branch that was one commit that denoted a merge from blank, but I am not seeing that.

Is there a common solution to this? I haven't been able to find anything.

Upvotes: 0

Views: 36

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520918

It seems that you sort of answered your own question in the title, but one way to avoid having the merge commit appear would be to rebase your local branch on the remote master. Change your workflow to this:

git add --all
git commit -m 'Now I'm rebasing...woohoo'
git rebase origin/master

# resolve merge conflicts, which may occur at the replay of each commit

git push --force -u branch/name

Comments:

The command git rebase origin/master will rebase your local branch (which may be anything related to master) on the remote master. As each commit from your local branch is replayed, you may encounter a merge conflict. After resolving the conflict, you can continue the rebase by typing git rebase --continue.

The command git push --force -u branch/name will overwrite the version of your local branch which exists on the remote. This is required because, in the process of doing the rebase on master, you actually rewrote the history of your branch.

Upvotes: 1

Related Questions