git push命令出错,remote端有修改的解决办法
Git push命令后出现如下提示:
遭拒是因为remote端有更改,解决方案如下:
Don’t worry, this is completely normal and happens all the time when working with remote repositories like GitHub.
What this error means
GitHub is rejecting your code because the cloud version of your project has updates that your local computer doesn’t know about yet.
This usually happens if:
- You (or a teammate) edited a file directly on GitHub.com (like updating a
README.md). - You committed new changes on your computer, and now your local computer and GitHub have split timelines.
Git has a strict rule: You must catch up to the cloud timeline before you can push your own changes.
How to Fix It (Step-by-Step)
Step 1: Fetch and Merge the Cloud Changes
Open your terminal and run a pull command. The safest way to do this is by using the --rebase flag, which neatly places your new local commits on top of whatever changes are currently on GitHub:
1 | git pull origin main --rebase |
(If you aren’t using rebase, a simple git pull origin main works too, though it might generate a generic “Merge branch…” commit message).
Step 2: Handle any Merge Conflicts (If they happen)
-
Scenario A (Most Common): If the files changed on GitHub were different from the files you worked on, Git will merge them automatically. You will see a success message. Move straight to Step 3.
-
Scenario B: If you and the cloud version edited the exact same line of the exact same file, Git will pause and say “Conflict.” Open that file in Typora or VS Code, look for the
<<<<<<< HEADmarkers, pick which code you want to keep, save the file, and run:1
2git add .
git rebase --continue
Step 3: Push Your Code Successfully
Now that your local computer is perfectly caught up with GitHub’s history, run your original command again:
1 | git push origin main |
Your changes will now fly right up to GitHub without any complaints!


