Git/empty

From Omnia
< Git
Jump to navigation Jump to search

Create Empty Branch

November 2021 Update: As of git version 2.27, you can now use git switch --orphan <new branch> to create an empty branch with no history.

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

Original solution:

git checkout --orphan empty-branch
git rm -rf .
git commit --allow-empty -m "root commit"
git push origin empty-branch

ref:

--

Use option --orphan to create branch with no parents.

git checkout --orphan new-empty-branch 
git rm -rf .
git commit --allow-empty -m "Initial commit on orphan branch"

ref: