l-x.github.io

Create an Empty Branch With Git

| Comments

Sometimes you need to create an emtpy branch, especially for GitHub’s project pages. Below you will find the most simple solutin I’ve found so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ git checkout --orphan gh-pages # create orphan branch
Switched to a new branch 'gh-pages'

$ git branch # make sure not to be in any branch
  master

$ git reset --hard HEAD # reset working tree

$ git commit --allow-empty -m "initial empty commit" # create empty commit, best practice
[gh-pages (root-commit) b00b135] initial empty commit

$ git branch # check if the new branch was created
* gh-pages
  master

Comments