Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a new clean branch in Git for a v2 rewrite

I'm getting ready to start version 2.0 of a library, a complete rewrite. I'll basically start from scratch, but I'd like to keep working within the same Git repository. I'm trying to figure out how to approach creating a clean new brach for the rewrite.

The naive way to start would be to create a new branch, and delete everything:

$ git checkout -b v2
Switched to a new branch 'v2'

$ rm -rf *
$ git commit -m "empty the branch for a clean slate"
$ git push origin v2

However, it's not ideal to have this commit that deletes everything in the branch. I'd like to be able to create a new empty branch, while keeping the commit history.

It seems like git checkout --orphan v2 will create a new empty branch, but it also has no parent.

Is there another way to create a clean empty branch without losing commit history?

like image 539
Hristo Avatar asked Oct 27 '25 10:10

Hristo


1 Answers

Your history will always be in the v1 branch. Ie master. When v2 becomes stable you can make that master and rename the old master to v1

Orphan is the best way way to start fresh

like image 84
exussum Avatar answered Oct 30 '25 00:10

exussum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!