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.
More on Submodules, LFS and Hooks
`fatal: No url found for submodule path 'libs/common' in .gitmodules`IntermediateAfter cloning, the submodule directories exist but are empty.Beginner`git submodule update` fails: `fatal: remote error: upload-pack: not our ref 3f2a9c1...` and `Fetched in submodule path 'libs/common', but it did not contain 3f2a9c1. Direct fetching of that commit failed.`Intermediate`git status` keeps showing `modified: libs/common (new commits)` even though you never touched it.BeginnerYou committed inside a submodule, ran `git submodule update`, and your commits vanished.Intermediate`git submodule add` fails with `fatal: 'libs/common' already exists in the index`.Intermediate