I made a few unstable commit changes that were also pushed. My imaginary commit tree is as follows:
A -> B -> C -> D
Commit "A" was the latest stable commit. Upon finding that the later changes were unstable, I went back to the last stable revision using
git checkout A
I then created a new branch "stable" with
git checkout -b stable
And continued working in that branch. Now I want to merge to master, but I don't want to delete the changes I previously had, so I wanted to add them to a new branch instead of using revert. Following the advice in this thread, I did the following from the master branch:
git branch unstable
git reset --hard HEAD~3
So now HEAD points to commit A, and the new branch "unstable" starts at commit B. But I want to merge my stable changes (in branch "stable") so I use
git merge stable
And it completes successfully with no conflicts, and HEAD now points to the latest revision with the the stable changes merged in. I can now push all branches to my repository except master, which reports a non-fast-forward error. If I pull, it seems to pull all the unstable changes I had from earlier.
There appears to be a large number of posts similar to this, but it seems that mostly people want to just use revert to undo the commits they had, whereas I want to keep my unstable commits, but in a separate branch as I have it now. What am I doing incorrectly?