我正在研究git,我在使用我在Github中创建的新存储库中推送现有文件时遇到了问题。
这就是我所做的:
- git init
- git add .
- git commit -m "This is the base code for the project"
https://github.com/myname/my_projects.git
- git remote add origin https://github.com/myname/my_projects.git
- git push origin master
然后在做推后我有这个错误:
λ git push origin master
Username for 'https://github.com': myname
Password for 'https://myname@github.com':
To https://github.com/myname/my_projects.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/myname/my_projects.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.
你能帮我解决这个问题吗?
答案 0 :(得分:3)
git push --force origin master
如果您确定要使用本地内容覆盖github遥控器上的内容。
答案 1 :(得分:2)
您可能使用README文件初始化了Github上的repo。如果是这样,您可以按照建议的早期答案进行操作,或者您可以先使用:
NumberDecimalDigits
您的分支机构不是最新的,因为遥控器有自述文件,而您没有此文件本地。拉完后,你必须再次提交,但是这样做会告诉Git你的本地分支是否与远程分支保持同步。
在此之后你可以像往常一样推动:
git pull origin master