Skip to content

Instantly share code, notes, and snippets.

@vlucas
Last active February 6, 2024 22:57
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vlucas/1a155a9b5ece5eb36d54 to your computer and use it in GitHub Desktop.
Save vlucas/1a155a9b5ece5eb36d54 to your computer and use it in GitHub Desktop.
Deploy a Static Site to Github Pages
#!/bin/bash
GIT_REPO_URL=$(git config --get remote.origin.url)
mkdir .deploy
cp -R ./* .deploy
cd .deploy
git init .
git remote add github $GIT_REPO_URL
git checkout -b gh-pages
git add .
git commit -am "Static site deploy"
git push github gh-pages --force
cd ..
rm -rf .deploy
@vlucas
Copy link
Author

vlucas commented Jun 3, 2015

Assumptions:

  • This script is placed in the root of the folder with all the static files and assets you want to put on GitHub pages

What this script does:

  1. Gets current Git repo URL
  2. Creates new .deploy folder (with a dot first so it won't get picked up by the cp command)
  3. Copies all files recursively to newly created .deploy folder and goes to that folder
  4. Initializes new git repo in the .deploy folder, and sets the URL to the Git repo URL
  5. Checks out a new gh-pages branch
  6. Adds all files, commits, and pushes to the gh-pages branch with a force deploy
  7. Cleans up and removes the .deploy folder

How to run this:

cd /folder/with/my/website
./deploy.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment