Automating deployment from Github: how to

Hey :wave: I read a few threads here and some mostly-outdated online articles about how to automate deployments from Github to Glitch, and just thought I would share my copy & paste solution.

:rotating_light: This will wipe away any code in your Glitch project and replace it with the code from Github, and reload your project, every time you push to your repo’s main branch.

In your Glitch project:

  1. Go to the Glitch đź’» Terminal and run the following:
git config receive.denyCurrentBranch ignore

cat << EOF > .git/hooks/post-receive
unset GIT_INDEX_FILE
git --work-tree=/app --git-dir=/app/.git checkout -f
refresh
EOF

chmod u+x .git/hooks/post-receive
  1. Go to 🧰 Tools, then Import / Export, and click the [ Copy ] button to copy :sparkles: your project’s Git URL :sparkles: to clipboard.

In your Github repo:

  1. Go to ⚙️ Settings, then Secrets and variables > Actions, and click [ New repository secret ] to add the following secret:

    • Name: GLITCH_GIT_URL
    • Secret: ✨ your project's Git URL ✨ (see previous step)
  2. Create a new Github Action, by committing a new file, .github/workflows/sync.yml:

name: Glitch Sync

on:
  push:
    branches:
      - main

jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - name: Sync to Glitch Project
        uses: wei/git-sync@v3
        with:
          source_repo: https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
          source_branch: main
          destination_repo: ${{ secrets.GLITCH_GIT_URL }}
          destination_branch: master

This Github Action will run every time you push to your repo’s main branch, and will update and refresh your Glitch project automatically.

9 Likes

I was not able to get this to work. There’s an official helpdesk article saying this approach is not supported. For automated deployment, I recommend reading this: https://help.glitch.com/hc/en-us/articles/16287554099213-Pushing-Local-Code-to-a-Project

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.