How to Fix “Push Rejected” in GitHub (2026 Guide)
The Short Answer
To fix the “Push Rejected” error in GitHub, advanced users can use the command git push -f to force push their changes, but be cautious as this can overwrite existing commits. Alternatively, use git push --force-with-lease to safely force push while avoiding overwriting other users’ changes.
Why This Error Happens
- Reason 1: The most common cause of the “Push Rejected” error is when the remote repository has been updated since the last time you pulled, and your local branch is not up-to-date. This can happen when multiple users are collaborating on the same repository and one user pushes changes before you do.
- Reason 2: An edge case cause of this error is when the Git configuration option
receive.denyCurrentBranchis set toupdateInsteadon the remote repository, which prevents pushing to the current branch if it’s not a fast-forward update. - Impact: The “Push Rejected” error results in a Git error, preventing you from pushing your changes to the remote repository, which can hinder collaboration and version control.
Step-by-Step Solutions
Method 1: The Quick Fix
- Go to Repository Settings > Branches > Branch permissions
- Toggle Update permissions to allow force pushes or set the default branch to a different branch that allows force pushes.
- Refresh the page and try pushing again.
Method 2: The Command Line/Advanced Fix
Use the command git push origin <branch-name> --force-with-lease to force push your changes while ensuring you don’t overwrite other users’ changes. This method is safer than a simple git push -f as it checks if the remote branch has been updated before forcing the push.
Prevention: How to Stop This Coming Back
- Best practice configuration: Regularly pull from the remote repository before pushing your changes to ensure your local branch is up-to-date.
- Monitoring tips: Use Git hooks or GitHub webhooks to notify team members when someone pushes changes to the repository, helping you stay aware of updates and avoid push rejections.
If You Can’t Fix It…
[!WARNING] If GitHub keeps crashing or you’re experiencing persistent issues with force pushes, consider switching to GitLab which handles force push fixes natively without these errors, offering more robust version control features.
FAQ
Q: Will I lose data fixing this?
A: Using git push -f can potentially overwrite existing commits, resulting in data loss. However, using git push --force-with-lease minimizes this risk by checking for updates before forcing the push.
Q: Is this a bug in GitHub? A: The “Push Rejected” error is not a bug in GitHub but rather a safety feature to prevent accidental overwriting of commits. This behavior has been present in Git since version 1.6.0, and GitHub’s implementation follows standard Git protocols.
📚 Continue Learning
Check out our guides on GitHub and Push Rejected.