I have two separate repos with these branches.
- dev-repo
- main -> prod-repo/main
- dev
- prod-repo
- main
- production
Prod-repo is always on branch “production” and is the running code of the webapp. My workflow to deploy is simple:
From dev-repo:
git checkout main
git merge dev
git push prod-repo
Then, from prod-repo
git checkout production #I understand this is redundant, but "just in case"
git tag -f last-stable
git merge main
(the tag allows me to quickly go back)
To automate this process and deploy when I push main, I made this post-receive hook that I put in prod-repo:
#!/bin/bash
git checkout production
git tag -f last-stable
if git diff --quiet main produccion; then
echo "No differences"
else
if git merge main; then
echo "Successful merge"
else
echo "Conflict detected, aborting merge..."
git merge --abort
fi
fi
Now, when I git push
from dev-repo I see two things that I didn’t expect:
- Output shows
remote: D <file>
for every single file in the repo, so it’s a freaking long log - When I
git status
from prod-repo, it suddenly has unstaged changes that perfectly “revert” the changes pushed, meaning the working directory didn’t get changed. The branches are merged ingit log
though.
I was expecting the hook to have the same behaviour as the commands being entered manually, but no. No ChatGPT or other Google search brought light into this.