2014-11-05 72 views
0

我想知道爲什麼我自己的代碼從我的桌面代碼庫沒有被推送到我在Github中創建的代碼庫中。將我自己的代碼添加到我自己的Github代碼庫中的錯誤

我做了以下內容:

cd "/your/repo/dir" 
git clone https://github.com/user_AKA_you/repoName # (creates /your/repo/dir/repoName) 
cp "/all/your/existing/code/*" "/your/repo/dir/repoName/" 
git add -A 
git commit -m "initial commit" 
git push origin master 

,我收到消息:

To https://github.com/skumar225/battleship.git 
! [rejected]  master -> master (non-fast-forward) 
error: failed to push some refs to 'https://github.com/skumar225/battleship.git' 
hint: Updates were rejected because the tip of your current branch is behind 
hint: its remote counterpart. Integrate the remote changes (e.g. 
hint: 'git pull ...') before pushing again. 
hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

什麼是錯誤,我怎麼能解決這個問題?

+0

你是克隆別人的回購再向上推到你的帳戶裸回購? – Omnikrys 2014-11-05 05:52:02

+0

我從我在GitHub中創建的存儲庫中克隆了repo URL。我不應該這樣做嗎?如果是這樣的話,你如何將新的代碼從桌面庫上傳到你在Github中創建的倉庫? – 2014-11-05 06:07:21

+0

不要克隆自己的回購。你想看看它。給我一分鐘我可以提出一個你可以使用的答案。 – Omnikrys 2014-11-05 06:08:17

回答

1

你想抓取和檢出你的github倉庫不克隆它。

如果你還沒有告訴git你是誰,你現在應該這樣做。您可以在每個存儲庫或全局執行該操作。爲了儘量減少問題,這應該符合你的github信息。我寧願做全球的,所以我不必再做了...

git config --global user.name "Your Name" 
git config --global user.email "[email protected]" 

設置本地倉庫

# make a directory for your working tree and git repository 
mkdir -p ~/projects/{src,git}/battleship 
# change directory to the git repository directory 
cd ~/projects/git/battleship 
# init the git repository (bare) 
git --git-dir ~/projects/git/battleship --work-tree ~/projects/src/battleship init 

添加遠程存儲庫,因此可以拉/推/從

# add your remote (github) repository (upstream) 
git remote add github [email protected]:skumar225/battleship.git 

從上游(github上)獲取和結帳

對於這部分工作你必須有an SSH key setup and assigned to ssh。它不一定要通過github來建立公共倉庫,但需要推動它。

# fetch from upstream 
git fetch github 
# checkout the master branch 
git checkout master 
# the files are all now in your working tree and ready to play with 

驗證你的工作樹填充

ll ~/projects/src/my-project 
# your local repo is now ready 
git status 

進行更改到工作樹

現在你有一個在github你的資料庫同步的本地存儲庫。爲了這個答案,我將添加一個文件並修改您可以提交的工作樹中的文件。

注意:這是所有的夜晚,咖啡因燃料,編碼補習班會議正常進行。

echo '** A new file has been created!' > ~/projects/src/battleship/newfile.md 
echo '- [x] Add new file' >> ~/projects/src/battleship/README.md 

臨時改變

之前,你可以提交你必須將它們暫存文件。如果你在分期前後做了一個狀態,你可以看到差異。

注:你仍然必須使用Git的目錄要做到這一點,而不包括--git-DIR

git status 
git add . 
git status 

提交到本地倉庫

最後,你可以提交到本地庫!

注意:如果您有更長的消息省略-m位,它將打開vim爲您添加更長的消息。

git commit -m "This is a test commit" 

推上游(github上)

此時所有剩下的上游推動它。這部分,因爲我不能做的是不是我的資料庫,但它是一個簡單的命令:

注:對於這部分的工作,你必須setup your credentials in github第一,所以它知道你是誰。

git push github 

了一個小竅門git的更容易在當地

我喜歡設定每個本地資源庫我保持一個別名。這使我可以使用git,而無需每次輸入 - git-dir或將我的目錄更改爲存儲庫。

alias gitbs='git --git-dir ~/projects/git/battleship' 

現在你可以使用別名(從任何地方)。

gitbs status 
gitbs add . 
gitbs push github 
# etc 

這只是直到你下一次登錄,雖然。要使其永久添加到你的〜/ .bashrc文件中。

+0

謝謝!欣賞這裏的細節,尤其是像我這樣的新手。 – 2014-11-06 04:36:19

+0

如果你仍然需要知道如何推到github上的裸回購,我也可以這樣做。真的,除非它是一個已經存在的項目,我通常只是讓github生成自述文件和許可證,然後把它拉出來。 – Omnikrys 2014-11-06 04:43:14

-2

確保你已經正確設置了遠程路徑(你的github repo ssh url)。

跳轉到項目文件夾上的終端

$ cd path_to_your_project_folder 

檢查的遠程信息狀態,以便你的資料庫

$ git remote show origin 

如果沒有設置則設置在這裏

$ git remote add origin paste_your_github_repo_ssh_url 

現在時間提交/推送您的項目

$ git push -u origin master 

> Reference

相關問題