2015-07-22 88 views
1

我正在學習git,並且在推送我在Github中創建的新存儲庫中的現有文件時遇到問題。如何推送新的Github存儲庫中的現有項目?

這裏就是我所做的:

  1. 我執行此我的項目- git init
  2. 我添加的文件在本地倉庫- git add .
  3. 我犯- git commit -m "This is the base code for the project"
  4. 然後我複製GitHub的倉庫URL裏面在我的Github頁https://github.com/myname/my_projects.git
  5. 然後我指出版本庫- git remote add origin https://github.com/myname/my_projects.git
  6. 然後,我把我的文件- 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. 

你能幫助我嗎?

+0

....你試圖把多個不同的項目到同一個GitHub庫? – NightShadeQueen

+0

不,只有一個項目 – Jerielle

回答

2

您可能使用README文件初始化Github上的回購。如果是這樣,你可以做早期的回答表明,或者您也可以與第一拉:

git pull origin master 

你的分支是不是最新的,因爲遙控器有一個README文件,你沒有這個文件本地。在你拉出之後,你將不得不再次提交,但是這樣做會告訴Git你的本地分支要與遠程分支保持同步。

這一點後,你可以做推像往常一樣:

git push origin master 
+0

是的你是正確的我創建了一個自述文件。好吧,我得到它你需要先執行拉取請求,因爲遠程有更新,接下來是推送。謝謝 – Jerielle

3

git push --force origin master如果您確定要用本地覆蓋您的github遠程桌面上的內容。

相關問題