Skip to content

Instantly share code, notes, and snippets.

@voscarmv
Last active November 5, 2025 00:06
Show Gist options
  • Select an option

  • Save voscarmv/51af777dbb8c8eb6118066a9c702aff6 to your computer and use it in GitHub Desktop.

Select an option

Save voscarmv/51af777dbb8c8eb6118066a9c702aff6 to your computer and use it in GitHub Desktop.
Set up a remote git repo that self pulls and runs

Set up a remote git repo that self pulls and runs

This emulates Vercel for node apps if you are running a remote VPS for instance or any self hosted environment.

Create bare git repo and clone your repo

On your remote host, VPS, etc, do

git init --bare ~/myrepo.git

Now in your local host, add it to your desired repo origins and push

cd ~/myrepo
git remote add origin username@mydomain.com:~/myrepo.git
git add .
git commit -m "Changes"
git push -u origin master # or main, whichever you use

Back on your remote host, clone the bare repo

git clone myproject.git myproject

Create post-receive

This will run every time you push changes. Because we will be running a node project from tmux, we will also add a tmux restarter for every time you push changes. This is an example for a typescript project.

cat << EOF > ~/myrepo.git/hooks/post-receive
#!/bin/bash

unset GIT_DIR
cd ~/myrepo
git pull origin master

tmux \
  send-keys \
  -t myrepo-session \
  C-c \
  'cd ~/myrepo' Enter \
  'npx tsc --build --verbose >> ~/myrepo.log 2>&1 && node dist/index.js 2>&1 | tee -a ~/myrepo.log' Enter
EOF

Create a start.sh script

To run your project:

cat << EOF > ~/start.sh
#!/bin/bash

tmux new-session -d -s myrepo-session
tmux \
  send-keys \
  -t myrepo-session \
  'cd ~/myrepo' Enter \
  'npx tsc --build --verbose >> ~/myrepo.log 2>&1 && node dist/index.js 2>&1 | tee -a ~/myrepo.log' Enter
EOF
chmod +x start.sh
./start.sh
EOF

Create a service to autostart on power on

If you want your project to run even on reboot, etc, create a new service thus

sudo cat << EOF > /etc/systemd/system/start-scripts.service
[Unit]
Description=My Startup Services
# Run after the network is up (optional, remove if no network needed)
After=network.target

[Service]
Type=forking
ExecStart=/home/username/start.sh
User=username
Restart=always
RestartSec=2

[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable start-scripts.service
sudo systemctl start start-scripts.service

To check out your app logs

Just

tail -f ~/myrepo.log

Some tmux tips

To attach the session tmux attach -t myrepo-session

Once you are done and want to leave the session running Ctr+b, d

To list all running sessions tmux list-sessions

To kill a session tmux kill-session -t myrepo-session, however this will just respawn if you are running a service.

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