Git/empty

From Omnia
< Git
Revision as of 21:49, 18 November 2026 by Kenneth (talk | contribs) (Created page with "== 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: [https://stackoverflow.com/qu...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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: