Fixing GitLab Push Issues with GitHub

I forgot to push to GitLab for three weeks. Switched machines, kept working on GitHub, and only noticed when I tried to clone from the homelab and got a repo that was 47 commits behind. My first fix was a pre-push hook. The hook tried to run git push to GitLab from inside git push to GitHub. That's how I learned that infinite recursion applies to git hooks too. There's a better way that requires zero scripts: git remote set-url --add --push origin https://lnkd.in/gBktpWyn git remote set-url --add --push origin http://gitlab.homelab/user/repo.git That's it. git push now sends to both. One command, nothing to remember. What happens when GitLab is unreachable (like from the corporate laptop): → GitHub ✅ → GitLab ⚠️ fails gracefully — push still succeeds to GitHub GitLab catches up next time I'm home. The 47-commit gap doesn't happen again. The hook that caused infinite recursion? Deleted. If you're writing a shell script to work around a git limitation, check the man page first. The feature is probably already there. #Git #DevOps #RemoteWork #GitHub

To view or add a comment, sign in

Explore content categories