Interview Prep/Git & GitHub/Submodules, LFS and Hooks

Pushing to a self-hosted Git server fails with `! [remote rejected] main -> main (pre-receive hook declined)`.

IntermediateTroubleshootingSubmodules, LFS and Hooks
Answer

Likely causes → A server-side hook rejected the push: commit message policy, file size limit, secret detection, forbidden paths, unsigned commits, or a direct push to a protected branch. The reason is printed in the remote: lines just above.

Diagnose → Scroll up for remote: output; then inspect the offending commits:

git log --format='%h %s' origin/main..HEAD
git diff --stat origin/main..HEAD

Fix → Fix the commits to satisfy the policy (git commit --amend, git rebase -i to reword or drop), then push again. If the hook is buggy, the server admin can check its logs (GitLab: gitlab-shell logs; Gitea/Bitbucket: hook output in admin UI).

Prevent → Mirror server-side rules as local hooks and CI checks so developers hit them earlier.

All Git & GitHub questions Roadmap: Git & GitHub

More on Submodules, LFS and Hooks