Deploying with git

Added 2022-01-02, Modified 2022-03-12

I read an article on setting up deployment via git push to your server. I found it ugly how they had two directories project.git (git dir) and project (work tree).

First I tried pushing to a normal repo, which diden't work except with an ugly workaround.

Then I realized I could do what the article said, but with project/.git being the bare repo

On server

# full path to project

# git will create needed directories
git init --bare $P/.git

cat <<EOF > $P/.git/hooks/post-receive
git --work-tree=$P checkout main --force
chmod +x $P/.git/hooks/post-receive

On dev machine

git remote add server ssh://[email protected]/full/path/to/project/.git
git push server