Skip to content

Instantly share code, notes, and snippets.

@SamuelDavis
Last active October 25, 2025 14:58
Show Gist options
  • Save SamuelDavis/171fc3c1fd2ea000477f9ca0768d728c to your computer and use it in GitHub Desktop.
Save SamuelDavis/171fc3c1fd2ea000477f9ca0768d728c to your computer and use it in GitHub Desktop.
Deploy to gh-pages for projects with `npm run build` to `dist/` (e.g. Vite)
function deploy() {
HOST=${1:-'[email protected]:SamuelDavis'}
DOMAIN=${2:-'sdavis.online'}
REMOTE_ORIGIN=$(git config --get remote.origin.url)
if [ $? -ne 0 ]; then
echo "Git repository not found." >&2
return
fi
REPO_NAME=$(basename -s .git $REMOTE_ORIGIN)
npm run build
if [ $? -ne 0 ]; then
return
fi
cd dist
echo "$REPO_NAME.$DOMAIN" > CNAME
git init
git add -A
git commit -m 'deploy'
BRANCH=$(git rev-parse --abbrev-ref HEAD)
git push -f "$HOST/$REPO_NAME.git" "$BRANCH:gh-pages"
cd -
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment