{"meta":{"title":"处理非快进错误","intro":"有时，Git 无法在不丢失提交的情况下对远程仓库进行更改。 发生此情况时，推送会被拒绝。","product":"开始","breadcrumbs":[{"href":"/zh/get-started","title":"开始"},{"href":"/zh/get-started/using-git","title":"使用 Git"},{"href":"/zh/get-started/using-git/dealing-with-non-fast-forward-errors","title":"非快进错误"}],"documentType":"article"},"body":"# 处理非快进错误\n\n有时，Git 无法在不丢失提交的情况下对远程仓库进行更改。 发生此情况时，推送会被拒绝。\n\n如果其他人已推送到与您相同的分支，Git 将无法推送您的更改：\n\n```shell\n$ git push origin main\n> To https://github.com/USERNAME/REPOSITORY.git\n>  ! [rejected]        main -> main (non-fast-forward)\n> error: failed to push some refs to 'https://github.com/USERNAME/REPOSITORY.git'\n> To prevent you from losing history, non-fast-forward updates were rejected\n> Merge the remote changes (e.g. 'git pull') before pushing again. See the\n> 'Note about fast-forwards' section of 'git push --help' for details.\n```\n\n可以通过[提取和合并](/zh/get-started/using-git/getting-changes-from-a-remote-repository)远程分支上所做的更改以及本地所做的更改来解决此问题：\n\n```shell\n$ git fetch origin\n# Fetches updates made to an online repository\n$ git merge origin YOUR_BRANCH_NAME\n# Merges updates made online with your local work\n```\n\n或者，只需使用 `git pull` 一次执行这两个命令：\n\n```shell\n$ git pull origin YOUR_BRANCH_NAME\n# Grabs online updates and merges them with your local work\n```"}