Many basic Git use cases involve a main branch
master with feature branches periodically merged into
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
1. setup blank Git branch
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.
- change to the repo directory, e.g.
create a blank Git branch
git checkout --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 you with nothing but the
.git/directory, which should not be disturbed.
2. copy documentation files
What happens next depends on if your documentation files were already added to another branch (tracked) or were not added to Git (untracked).
Wanted files for the blank
gh-pages branch are in
copy over the files to
git checkout master -- docs/ git commit -am "moved docs from master"
3. Upload files to GitHub
push the documentation
git push -u origin gh-pages
Enable the documentation builds from
https://github.com/username/myrepo/settings→ GitHub Pages under Source select
In a few minutes, the webpages at
https://username.github.io/myrepo/should be active.
Once you’re sure everything is working, you can remove the
docs/ folder from its old location.