git push update rejected because the remote repository contains commits not present locally
After improving a Hugo theme used by this blog called bobobk-hugo, I encountered the following error when pushing to the git repository:
(base) ➜ bobobk-hugo git:(master) git push origin
Username for 'https://github.com': tengbozhang
Password for 'https://tengbozhang@github.com':
To https://github.com/tengbozhang/bobobk-hugo.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/tengbozhang/bobobk-hugo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Git’s message indicates that the remote repository contains commits that do not exist in your local repository. This means the GitHub repo has updates that your local copy hasn’t pulled yet, so Git prompts you to merge remote changes before pushing. The solution is simple:
First pull the latest version from GitHub, then push your changes again, and it will succeed.
git pull
git add .
git commit
## Remove some comment information
git push origin
# Push the local version to the remote GitHub repository
- 原文作者:春江暮客
- 原文链接:https://www.bobobk.com/en/937.html
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。