Skip to content

Instantly share code, notes, and snippets.

@doramatadora
Last active November 3, 2023 20:14
Show Gist options
  • Save doramatadora/6acd73864a91989f8b2175df05156bb5 to your computer and use it in GitHub Desktop.
Save doramatadora/6acd73864a91989f8b2175df05156bb5 to your computer and use it in GitHub Desktop.
Automate Git -> Glitch repo sync via Github Actions

Automating deployments from Github to Glitch

💅 Copy & Paste 💅

🚨 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 ✨ your project's Git URL ✨ to clipboard.

In your Github repo:

  1. Go to ⚙️ Settings, Secrets and variables, then 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

That's it, that's the whole thing.

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