2011-10-07 101 views
68

我正在測試Git和Bitbucket。如何將本地更改推送到bitbucket上的遠程git存儲庫

我在Bitbucket上創建了一個存儲庫,並創建了一個本地副本,並將文件提交到它。我似乎無法將文件從本地回購站推送到遠程回購站。

下面是我在做什麼:

git clone https://[email protected]/me/test.git 
cd test 
touch dummy 
git add dummy 
git commit dummy -m "my first git commit" 
git push 

最後一行輸出:

Everything up-to-date 

,當我登錄到我到位桶看到水溼我的虛擬文件。

我在做什麼錯?

編輯:

這樣做的工作:

git push origin master:master 

任何解釋爲這一點,一個簡單的git push之間的區別?

+0

任何新的與git看到這個問題時,請查看http://stackoverflow.com/questions/5713563/reasons-for-not-working-on-the-master-branch-in-git – JGallardo

回答

85

改爲使用git push origin master

您在本地存在一個存儲庫,並且最初的git push正在「推送」它。沒有必要這樣做(因爲它本地),它顯示一切都是最新的。 git push origin master指定遠程存儲庫(origin)和位於那裏的分支(master)。請參考this resource

+0

感謝說明。 – Joel

+2

我還應該提到,當你克隆一些東西時,'origin'庫是自動定義的。 –

+0

好的,謝謝。我想擺脫svn的思維模式。 – Joel

14

這是一項安全措施,以避免推送尚未準備好發佈的分支。鬆散地說,通過執行「git push」,只會推送服務器上已存在的具有相同名稱的本地分支,或使用localbranch:remotebranch語法推送的分支。

爲推動各地方分支機構到遠程倉庫,使用--all

git push REMOTENAME --all 
git push --all 

或指定要推動所有分支:

git push REMOTENAME master exp-branch-a anotherbranch bugfix 

此外,它是非常有用的添加-u到「git push」命令,因爲這會告訴你,如果你的本地分支在遠程分支之前或之後。在git獲取後運行「git status」時會顯示此信息。

8

我與Git下載從https://git-scm.com/set up ssh按照指令https://stackoverflow.com/a/26130250/4058484的答案。

一旦生成的公鑰是我的到位桶帳戶驗證,並參照作爲explaned上http://www.bohyunkim.net/blog/archives/2518的步驟我發現,剛「混帳推」工作:

git clone https://[email protected]/me/test.git 
cd test 
cp -R ../dummy/* . 
git add . 
git pull origin master 
git commit . -m "my first git commit" 
git config --global push.default simple 
git push 

殼牌迴應情況如下:

$ git push 
Counting objects: 39, done. 
Delta compression using up to 2 threads. 
Compressing objects: 100% (39/39), done. 
Writing objects: 100% (39/39), 2.23 MiB | 5.00 KiB/s, done. 
Total 39 (delta 1), reused 0 (delta 0) 
To https://[email protected]/me/test.git 992b294..93835ca master -> master 

它甚至適用於對在GitHub上

01合併 master to gh-pages
git checkout gh-pages 
git merge master 
git push 
相關問題