So you just finished a new feature, committed it, and are now ready to push it out of the nest and up to origin. But then you get this:
To firstname.lastname@example.org:juliomistral/TestMainRepo.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'email@example.com:juliomistral/TestMainRepo.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
So you then follow the instructions and you get this little gem:
Merge branch 'master' of github.com:juliomistral/TestMainRepo # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
Which results in this history:
* 8f7e922 (HEAD, master) Merge branch 'master' of github.com:juliomistral/TestMainRepo - Julio A. Mistral, 4 seconds ago |\ | * 1dc0a3d (origin/master, origin/HEAD) Another commit that happened and was pushed up - Julio A. Mistral, 7 minutes ago * | 6bf4e46 New feature to be pushed up - Julio A. Mistral, 8 minutes ago |/ * 1413896 Test checkin on local branch tracking master - firstname.lastname@example.org, 1 year, 6 months ago * 710c1d3 Initial commit - email@example.com, 1 year, 6 months ago
Bigger sad (unless you like multi-color ASCII art, in which case go buck wild).
This just irks me: you end up committing a merge that has zero relevancy. There was no conflict to resolve and you weren't even merging another branch into master. You just wanted to push your change up.
So this is what you do:
# Preserve any local changes you have # that will get blown away with next step git stash save # Reset to last commit before merge bubble commit git reset --hard HEAD~1 # Pull with rebase git pull --rebase # Push your change up, guilt free git push origin HEAD
And now you have a clean, bubble free history
* 8f34b08 (HEAD, origin/master, origin/HEAD, master) New feature to be pushed up - Julio A. Mistral, 10 minutes ago * 1dc0a3d Another commit that happened and was pushed up - Julio A. Mistral, 9 minutes ago * 1413896 Test checkin on local branch tracking master - firstname.lastname@example.org, 1 year, 6 months ago * 710c1d3 Initial commit - email@example.com, 1 year, 6 months ago