Skip to content

Instantly share code, notes, and snippets.

@bleft
Last active April 21, 2017 09:08
Show Gist options
  • Save bleft/935fa24aad8012eef6465ac82da6bb0a to your computer and use it in GitHub Desktop.
Save bleft/935fa24aad8012eef6465ac82da6bb0a to your computer and use it in GitHub Desktop.
git: change branch to master
The problem with the other two answers is that the new master doesn't have the old master as an ancestor, so when you push it, everyone else will get messed up. This is what you want to do:
git checkout better_branch
git merge --strategy=ours master # keep the content of this branch, but record a merge
git checkout master
git merge better_branch # fast-forward master up to the merge
If you want your history to be a little clearer, I'd recommend adding some information to the merge commit message to make it clear what you've done. Change the second line to:
git merge --strategy=ours --no-commit master
git commit # add information to the template merge message
# GIT commit --amend rückgängig machen:
# Move the current head so that it's pointing at the old commit
# Leave the index intact for redoing the commit.
# HEAD@{1} gives you "the commit that HEAD pointed at before
# it was moved to where it currently points at". Note that this is
# different from HEAD~1, which gives you "the commit that is the
# parent node of the commit that HEAD is currently pointing to."
git reset --soft HEAD@{1}
# commit the current tree using the commit details of the previous
# HEAD commit. (Note that HEAD@{1} is pointing somewhere different from the
# previous command. It's now pointing at the erroneously amended commit.)
git commit -C HEAD@{1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment