Skip to content

Instantly share code, notes, and snippets.

@ceer
Last active January 6, 2023 18:04
Show Gist options
  • Save ceer/fac07a12f757f2a62c9a8c7def7532f3 to your computer and use it in GitHub Desktop.
Save ceer/fac07a12f757f2a62c9a8c7def7532f3 to your computer and use it in GitHub Desktop.
deploy git branch hook
#!/bin/sh
read oldrev newrev ref
branchname=${ref#refs/heads/}
GITDIR=/path/to/bare.git
TARGET=/path/to/files
git --work-tree=$TARGET --git-dir=$GITDIR checkout --force ${branchname}
@ceer
Copy link
Author

ceer commented Nov 24, 2021

Install

git init --bare bare.git
curl -L -o repo.git/hooks/post-receive https://gist.github.com/ceer/fac07a12f757f2a62c9a8c7def7532f3/raw/b1deb781ee37c87b967aba80d466c1bdad908436/post-receive
chmod +x repo.git/hooks/post-receive

@ceer
Copy link
Author

ceer commented Nov 24, 2021

@ceer
Copy link
Author

ceer commented Jul 3, 2022

Use locally

cd project
git remote add preprod user@preprod:preprod.git
git checkout feature
git push preprod feature

git remote add live user@prod:prod.git
git checkout main
git push live

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