2016-08-23 155 views
0

我有一個remote git repository,我有一個remote_branch。 我將remote_repository克隆到我的機器上,並創建了一個local_branch遠程和本地存儲庫

我現在想要push將我的local_branch更改爲remote_branch。 做的是,我設置了upstream flag

git branch --set-upstream-to=origin/remote_branch local_branch 

然後我commitstage我的變化,並嘗試git push的改變上remote_branch。 我得到這個消息:

To [email protected] 
! [rejected]  remote_branch -> remote_branch (non-fast-forward) 
error: failed to push some refs to '[email protected]' 
hint: Updates were rejected because a pushed branch tip is behind its 
remote counterpart. If you did not intend to push that branch, you may 
want to specify branches to push or set the 'push.default' 
configuration variable to 'simple', 'current' or 'upstream' to push 
only the current branch. 

然而,當我push的通過

git push origin local_branch:remote_branch 

它的工作原理改變。 我在做什麼錯?

回答

1

在您的本地機器上,您似乎正在使用名爲remote_branch的分支。從遠程存儲庫克隆時,該分支會自動在本地計算機上創建。當您發出git push時,默認情況是推送來自當前分支的更改。因此,您需要首先執行git checkout local_branch(並在那裏提供提交)。

一般來說,我建議在本地使用與遠程存儲庫相同的名稱,並使用1:1映射。

+0

我做了git checkout local_branch - >沒有做伎倆,, – Stophface

+0

再次讀它,可能是你添加了你的修改(提交)到'local_branch',而其他人增加了其他提交到遠程存儲庫?如果是這種情況,您可能需要合併或重新整理所做的更改,然後才能推送(而另一個推送則因爲它實際上什麼都不推送)。 'gitk --all'可以幫助可視化當前狀態。 –

+0

nope。我從'local_branch'上的'remote_branch'中取出,然後在'local_branch'中改變了一些東西,並嘗試將'local_branch'推送到'remote_branch'。同樣的效果。 – Stophface

相關問題