Really Simple Staging preserving .data and .env

I am developing an application using glitch. I would like to be able to push it from a dev copy to a demo copy, and then to production manually. I understand I could probably export to github and build workflows and CI to do all this, or develop using an ide on my laptop. I also read a similar forum post where they landed on swapping out project names. But I like to stay in the web editor, and swapping project names ignores the .env and .data folders, which need to stay. What I really want is:

  • develop foo-dev in the web-based glitch editor.
  • open the web based terminal and run one command (or a shell script I write) to push all of the code, but NOT .env or .data to foo-demo or foo-prod.

I am able to get close if I:

  • ensure .env and .data are in .gitignore
  • from foo-dev terminal “git commit”
  • from foo-demo terminal “git remote add dev https://path-to-foo-dev/git/foo-dev.git” once, then as-needed “git pull dev master --no-edit” and “refresh”

However, this requires me to touch both foo-dev and foo-demo each publish. I’d really like to push. When I try this:

  • from foo-dev terminal “git remote add demo https://path-to-foo-test/git
  • from foo-dev terminal “git commit” and then “git push demo master -f”

I get an error “refusing to update checked out branch”.

Thanks to SO, I was able to get around this with git config receive.denyCurrentBranch updateInstead from the foo-demo terminal.

But when I do this, as best I can tell, foo-demo never gets updated. I’m sure there’s something I’m missing - I’m beyond my basic understanding of git here. But in the end: Is there some easy way to push code from one project to another, without involving github or laptop, taking care to not overwrite .data and .env?

the last step is probably to run refresh on foo-demo so that glitch relaunches the project with the new code. maybe you could do it with a git hook of some sort in foo-demo.

can you look up what git hooks the version of git on glitch supports?

Still needs some testing, but that pointed me in the right direction. I didn’t know about git hooks at all.

On the receiving project terminal, run:

git config receive.denyCurrentBranch updateInstead 
echo 'refresh' > ./.git/hooks/post-update
chmod +x ./.git/hooks/post-update

Then when it’s pushed into, the project refreshes. Exactly what I want - I just need to test some more to see if there are any gotchas.

1 Like

After some more testing, this is working great. To recap for others (or me in the future), below is a summary of the solution:

Create multiple projects. We’ll call one foo-dev and the other foo-prod. Do these steps to set up publishing from foo-dev to foo-prod:

In foo-prod, open a terminal and run the following to tell git to update automatically on a push and add a “hook” to refresh glitch when a push is received:

git config receive.denyCurrentBranch updateInstead 
echo 'refresh' > ./.git/hooks/post-update
chmod +x ./.git/hooks/post-update

Then copy your git url (Tools → Import/Export)

Switch to foo-dev, edit your .gitignore file to ensure it contains .env and .data, node_modules, and any other files/folders you dont want published to production automatically.

Then, create a file and paste the following to create a script that will commit any pending changes and push them to a production remote:

git commit -a -m "Publishing Update"
git push prod master --force

In foo-dev, open a terminal and run the following to add the remote and make the script above executable:

git remote add prod <git url from foo-prod>
chmod +x ./

Now, whenever you make changes in foo-dev and are ready to publish, you can just run the following from terminal:


Of course, you’re not limited to dev and prod. You can also do similar for a demo environment, multiple production environments, etc. You could add in logic to run tests, notify, etc. I think this would be a cool feature for glitch to implement in the UI, but getting all this down to one command is pretty helpful.


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