Git push rejections can interrupt your workflow and prompt a search for the underlying cause. Rather than relying on memorized commands to bypass errors, pinpointing the specific rejection reason helps keep version control and teamwork on track.
Decoding the Bracketed Diagnosis
When Git blocks a push, it shows a status line with a word or phrase in brackets. This bracketed message spells out the reason for the refusal. For instance, you might encounter ! [rejected] main -> main (fetch first) or similar output. The bracketed reason at the end points directly to the fix.
Common Git Push Rejection Cases
Most developers run into these rejection reasons early on:
- (fetch first): The remote repository has a commit you have not fetched.
- (non-fast-forward): You have fetched the latest changes, but your branch still lags behind the remote branch.
- (stale info): A push with --force-with-lease was blocked because the remote branch changed since your last fetch.
Case 1: fetch first
If a teammate pushes changes while you work locally, your next push might trigger:
! [rejected] main -> main (fetch first) error: failed to push some refs to '/tmp/lab/remote.git' hint: Updates were rejected because the remote contains work that you do not hint: have locally. This is usually caused by another repository pushing to the same ref. If you want to integrate the remote changes, use 'git pull' before pushing again.
Here, Git detects new work on the remote but cannot see its content until you fetch.
Case 2: non-fast-forward
After running git fetch but before merging or rebasing, pushing again can result in:
! [rejected] main -> main (non-fast-forward) error: failed to push some refs to '/tmp/lab/remote.git' hint: Updates were rejected because the tip of your current branch is behind its remote counterpart. If you want to integrate the remote changes, use 'git pull' before pushing again.
At this point, Git sees your branch lacks the latest remote commit and blocks the push to avoid overwriting someone else's work.
How to Fix fetch first and non-fast-forward
To address both cases, bring the remote changes into your branch. You can do this by rebasing or merging:
git pull --rebase origin main git push origin main
If your team uses merge commits, try git pull --no-rebase instead. After integrating, both your commit and your teammate's commit remain in the branch history:
759241a bob adds a line b3f7a12 alice adds a line f855287 first commit
Case 3: stale info
When you amend a commit and push with --force-with-lease, but someone else has pushed in the meantime, you may see:
! [rejected] main -> main (stale info) error: failed to push some refs to '/tmp/lab/remote.git'
This message means --force-with-lease stopped you from overwriting new work you have not seen. There is no hint here. To move forward, fetch the latest changes and review what has landed:
git fetch git log --oneline HEAD..origin/main
Inspecting Remote References and Commit IDs
To get a clearer picture of the remote repository before pushing, use the git ls-remote command. The official Git documentation explains that this command lists references in a remote repository along with their commit IDs. This helps you check the exact state of branches and tags on the remote, which matters in collaborative and educational settings where knowing the current repository state helps avoid conflicts and push rejections.
Avoiding Destructive Pushes
Using git push --force skips all these safeguards and can erase others' commits from the branch. The solutions above avoid force pushing and support a safer, more collaborative workflow.
Further Learning and Practice
To try out these scenarios, find a script that reproduces the output on GitHub at circuittimes/git-push-rejected-lab. For a broader look at Git concepts and building real confidence with version control, see this practical guide.
For more advanced cases, including tags, hooks, protected branches, and server settings, check the full guide at Circuit Times, which matches each cause to its exact hint line.
Disclosure: Circuit Times used Claude, an AI model made by Anthropic, to help prepare this post. Circuit Times is responsible for the checks and the conclusions.
