Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@blattmann
Last active October 9, 2023 22:40
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save blattmann/4bc90557c2bc2907e715f45ec35674a2 to your computer and use it in GitHub Desktop.
Save blattmann/4bc90557c2bc2907e715f45ec35674a2 to your computer and use it in GitHub Desktop.
Git: Create empty branch

Replace empty-branch with your desired branch name.

git checkout --orphan empty-branch

Then you can remove all the files you'll have in the staging area (so that they don't get committed):

git rm -rf .

At this point you have an empty branch, on your machine.

Before you can push to GitHub (or any other Git repository), you will need at least one commit, even if it does not have any content on it (i.e. empty commit), as you cannot push an empty branch

git commit --allow-empty -m "root commit"

Finally, push it to the remote, and crack open a beer :)

git push origin empty-branch

@ronnieotieno
Copy link

Thanks, man!!

@ronnieotieno
Copy link

You can do all those then run git pull remoteName/branch_name. But I guess there is a better way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment