Many basic Git use cases involve a main branch with feature branches periodically merged into the main branch.
For certain purposes, totally distinct branch without a common history can exist in the same Git repo.
One of the most common uses of this is for documentation.
For example, GitHub will build a website from the
Do NOT force push during this procedure, you may accidentally erase years of work!
This example assumes you want to create a
gh-pages empty branch for documentation on GitHub, but will of course work for other purposes too.
From the repo directory create a blank Git branch:
git switch --orphan gh-pages
Remove the unneeded files from this branch (by default, all existing files are staged from the previous branch)
git rm --cached -r . git clean -id
This leaves the
.git/ directory, which should not be disturbed.
What happens next depends on if your documentation files were already added to another branch (tracked) or were not added to Git (untracked).
Assume wanted files for the blank
gh-pages branch are in
copy over the files to
git checkout main -- docs/ git commit -am "moved docs"
push the documentation
git push -u origin gh-pages
Enable the documentation builds from github.invalid/username/myrepo/settings → GitHub Pages under Source select
In a few minutes, the webpages at username.github.io/myrepo/ should be active.
Once everything is working, the old
docs/ folder isn’t needed.