This command will create a branch with no parent (no commit history) on a repo.
git checkout --orphan <new-branch>
Manage folders linked to others branches of your repo.
Do not confuse them with git submodules which are links to different repositories.
You can create a folder in wich a branch of your repository is checked out.
Exemple for Github Pages with a specific branch providing the static files:
- Create a new orphan branch:
git checkout --orphan gh-pages - Clean all (untracked) files:
git reset --hardorgit rm -rf . - Create first commit:
git commit --allow-empty -m "Initializing gh-pages branch" - Push the new branch on your repo:
git push origin gh-pages - Get back to your main branch:
git checkout master - Create the worktree in a
publicfolder:git worktree add -B gh-pages public origin/gh-pages
Now, all the files put in the public folder can simply be committed and pushed to the gh-pages branch.
Example: cd public && git add --all && git commit -m "Published to gh-pages" && git push origin gh-pages.
The rest of your repo will stay in sync with your main branch.
To be sure to not mess with your main branch you can add the folder containing the worktree in your .gitignore file.