你想抓取和檢出你的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文件中。
你是克隆別人的回購再向上推到你的帳戶裸回購? – Omnikrys 2014-11-05 05:52:02
我從我在GitHub中創建的存儲庫中克隆了repo URL。我不應該這樣做嗎?如果是這樣的話,你如何將新的代碼從桌面庫上傳到你在Github中創建的倉庫? – 2014-11-05 06:07:21
不要克隆自己的回購。你想看看它。給我一分鐘我可以提出一個你可以使用的答案。 – Omnikrys 2014-11-05 06:08:17