Create a new Git branch with no history

by

Sometimes you just want to have a fresh workspace in which to imagine, but don't want to trample or even fuss with existing code. And, logically, it'd be nice if this sketch code could live near the code it will eventually replace. Say, on a branch in that same codebase. Wouldn't that be nice? That'd be nice. And saints be praised it turns out there's a way to do it!

Normally, I just create a branch, rm -rf everything in the directory, and then push that. Don't do that.

Do this:

git switch --orphan <new branch>
git commit --allow-empty -m "Initial commit on orphan branch"
git push -u origin <new branch>

Thanks, StackOverflow!

Also, Happy New Year!

More posts

Comments powered by Talkyard.