How can I copy the content of a branch to a new local branch?

serengeti12 picture serengeti12 · Feb 21, 2013 · Viewed 331.4k times · Source

I have worked on a local branch and also pushed the changes to remote. I want to revert the changes on that branch and do something else on it, but I don't want to lose the work completely. I was thinking of something like create a new branch locally and copy the old branch there, then I can revert the changes and continue working on the old branch. Is there a better way maybe? Or how do I do this?

Answer

Daniel Hilgarth picture Daniel Hilgarth · Feb 21, 2013
git checkout old_branch
git branch new_branch

This will give you a new branch "new_branch" with the same state as "old_branch".

This command can be combined to the following:

git checkout -b new_branch old_branch