How to create an empty branch in a Git repository

Linux

I have an application code maintained in a Github repository. Now our requirement is to create documents for that application and save them under a separate branch in the same repository. I am simply trying to create a new branch but it links to the master branch. After googling it, I found an option --orphan to create a branch with no parent.

This tutorial will help you create a new empty branch in a Git repository.

Git Create empty branch

We can use --orphan command line option to create a new branch with no parent.

git checkout --orphan new-empty-branch 

The above command will create a new branch with no parent. You can now delete files from the working directory so they don’t switch to a new branch.

git rm -rf . 

Now you can add new files to this new branch, commit and push them to the remote git repository.

Hope this helps!

Source link

Share: