You committed on main, then the server rejected your push. Your commits are still in your local repository. If the branch rules block direct pushes, you can push those commits on a feature branch and open a pull or merge request into main.
Check what the server rejected
Read the reason on the [remote rejected] line and check any remote: lines for details. For example:
remote: Protected branch hook declined
Many server checks can produce pre-receive hook declined. Continue once the server message or the repository’s branch rules confirm that your account is blocked from pushing directly to the target branch.
Put your commits on a feature branch
In this example, the push to main on origin was rejected. Check your current branch and the remote’s fetch and push URLs:
git status --short --branch
git remote -v
Replace origin and main with the remote and destination branch from your rejected push. If the remote fetches from a different repository than it pushes to, or lists several push URLs, add a separate remote for the repository where you’ll open the request:
git remote add review-target \
https://git.example.com/acme/web.git
Run git remote -v again to confirm that the new remote has one push URL and that its fetch URL points to the same repository. Use review-target in both commands below so your feature branch tracks the repository you push to.
Fetch the target branch. The log lists commits your current branch has that the target lacks.
git fetch --no-tags --no-prune \
--no-prune-tags origin refs/heads/main &&
git log --oneline FETCH_HEAD..HEAD
Continue if the list shows your commits and every one belongs in the review. If it includes unrelated commits, start from the target branch and bring over only the commits for this change.
If your commits are still unpublished and your local main tracks the protected branch in that same repository, you can also move the commits off your local main before pushing. To keep your local main where it is, create a feature branch at your current commit and push it by name:
git switch -c fix/cart &&
git push --no-follow-tags \
--recurse-submodules=check \
-u origin HEAD:refs/heads/fix/cart
Use a fresh feature branch name in both places. If you’re already on the intended feature branch, skip git switch -c and use that branch’s name as the push destination. The push sends committed changes. Any uncommitted edits stay local.
If Git reports missing submodule commits, review and publish them separately to the submodule repository your team uses, then retry the feature-branch push.
Open the pull or merge request
In the repository you pushed to, choose fix/cart as the source and the protected branch, main here, as the target. Review the diff before opening the request. Your team’s usual checks and approvals apply.
For repositories you maintain, see how to prevent accidental pushes to production.
Check the branch before you push
On a Mac, push& (Pushand) shows which branches have unpushed commits and lets you review what’s waiting.