Git – Create a New Empty Branch

To do this in Git, we can create a new branch as an orphan. What is an orphan branch? It is a new branch without any commit.

Please note that you need to install Git v1.7.2 or higher in order to use --orphan option in the git command.

OK, here is step by step how to create a new empty branch:
 

1. Create an orphan branch

git checkout --orphan mybranch

 

2. Delete everything in the branch

git rm -rf .

 

3. Make some changes & commit

touch test.txt
git add test.txt
git commit -m "Adding a test file"

 

4. Push commits made on the local branch to the remote repository

git push origin mybranch

 
We’re done!

0 0 vote
Article Rating
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x