Skip to content

Instantly share code, notes, and snippets.

@vlucas
Last active Sep 22, 2020
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@vlucas 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