2016-08-23 164 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

相关问题