如何推送新的Github存储库中的现有项目?
问题描述:
我正在学习git,并且在推送我在Github中创建的新存储库中的现有文件时遇到问题。如何推送新的Github存储库中的现有项目?
这里就是我所做的:
- 我执行此我的项目
- git init
- 我添加的文件在本地仓库
- git add .
- 我犯
- git commit -m "This is the base code for the project"
- 然后我复制GitHub的仓库URL里面在我的Github页
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://[email protected]':
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.
你能帮助我吗?
答
您可能使用README文件初始化Github上的回购。如果是这样,你可以做早期的回答表明,或者您也可以与第一拉:
git pull origin master
你的分支是不是最新的,因为遥控器有一个README文件,你没有这个文件本地。在你拉出之后,你将不得不再次提交,但是这样做会告诉Git你的本地分支要与远程分支保持同步。
这一点后,你可以做推像往常一样:
git push origin master
+0
是的你是正确的我创建了一个自述文件。好吧,我得到它你需要先执行拉取请求,因为远程有更新,接下来是推送。谢谢 – Jerielle
答
git push --force origin master
如果您确定要用本地覆盖您的github远程桌面上的内容。
....你试图把多个不同的项目到同一个GitHub库? – NightShadeQueen
不,只有一个项目 – Jerielle