Skip to content

Instantly share code, notes, and snippets.

@korutx
Created September 9, 2024 14:55
Show Gist options
  • Save korutx/9cc3595628af37c09c0b0a10ae2770fb to your computer and use it in GitHub Desktop.
Save korutx/9cc3595628af37c09c0b0a10ae2770fb to your computer and use it in GitHub Desktop.
Create a disconnected git branch
#!/bin/bash
# Create a disconnected git branch for GitHub Pages
# Clone the repository without checking out files
git clone --no-checkout https://github.com/yourusername/yourrepo.git
cd yourrepo
# Create a new orphan branch
git checkout --orphan gh-pages
# Remove all files from the working directory
git rm -rf .
# Create an empty README.md and make the first commit
echo "# GitHub Pages" > README.md
git add README.md
git commit -m "Initial commit for GitHub Pages"
# Clean up any untracked files
git clean -fdx
# Push the new branch to origin
git push origin gh-pages
echo "Disconnected gh-pages branch created and pushed to origin."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment