Skip to content

Instantly share code, notes, and snippets.

@jericbas
Created March 11, 2023 13:44
Show Gist options
  • Save jericbas/f0ae9dc393ad6b87cdef71ddd328db47 to your computer and use it in GitHub Desktop.
Save jericbas/f0ae9dc393ad6b87cdef71ddd328db47 to your computer and use it in GitHub Desktop.
Build Gatsby and push the contents of the public directory to another branch
#!/bin/bash
# Build the Gatsby site
npm run build
# Create a new branch for the build files
git branch build-files
# Checkout the new branch
git checkout build-files
# Remove all files from the branch except the .gitignore file
git rm -r --cached .
git reset -- .gitignore
# Move the contents of the public/ directory to the root of the branch
mv public/* .
# Commit the changes
git add .
git commit -m "Add build files"
# Push the changes to the remote branch
git push -u origin build-files
# Switch back to the previous branch
git checkout -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment