In git, I’ve been making commits onto the master branch, when really I should have been working on a feature branch. I want to change this so that master is back to where it started, and what was on master is now on a new branch. Basically, my commit history looks like this:
A -- B -- C -- D -- E
| |
| master
origin/master
And I want it to look like this:
master
|
A -- B -- C -- D -- E
| |
| new_branch
origin/master
How can I change where master points?
git stashgit branch new_branchgit reset --hard origin/mastergit checkout new_branchgit stash popStash/unstash is not necessary if your working tree is clean. Just make sure there are no changes in your working tree, because those will be removed when you reset –hard
Another possibility (faster, and without the need to stash and reset):
git checkout -b new_branch mastergit branch -f master origin/master