I have a Git repository set up. This repository has almost 700 commits, but all of them is in the master branch. I would like to take an approach in which I roll back this master branch (this rollback involves roughly 50 commits) to an earlier point to make it stay there and starting from that point, branch out all later commits into a separate branch.

Graphical explanation

Current state:

|-.---.---.---.---.---.---.---.---+ master
 aaa bbb ccc ddd eee fff ggg hhh  HEAD

Desired state:

|-.---.---.--\-|  master
 aaa bbb ccc  \
                \.---.---.---.---.---+ seperate-branch
                ddd eee fff ggg hhh  HEAD

So that the master branch is rolled back to the ccc commit and every commit from that point (ddd and onwards) are moved into a seperate-branch.

I am fairly new to Git but have got myself to the journeyman levels, still this advanced usage is pretty above my head. I am using Ubuntu 11.04 as my system. The repository (apart from being stored locally) is having a remote set up to GitHub (if this is to make any difference).


You need to know the commit you want to rollback to, I'm calling it SHA1

git checkout -b seperate-branch
git checkout master
git reset SHA1 --hard

And you're done.

To push it on GitHub, you will need to do

git push --force origin master

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.