为什么我总是从我自己的远程git仓库中落后一个?

时间:2015-05-08 17:13:07

标签: git git-push

每当我尝试将更改推送到我自己的git repo时,我都会收到错误:

error: failed to push some refs to '--myrepo-here--'
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.
Completed with errors, see above

这是我的工作流程。
我们有一个git repo。 [主人]
团队中的每个人都分配了主要的回购。

  1. 在您的仓库中进行一些更改(本地)。
  2. 将更改推送到您自己的远程仓库。创建合并请求。
  3. 在您的仓库中进行一些更改(本地)。同时合并请求获得批准。
  4. 从[master]远程仓库中提取所有内容。
  5. 将更改推送到您自己的远程仓库。创建合并请求。
  6. 无论如何,没有人可以推送我的回购。但我经常收到这个错误。它说我从遥远的回购中落后了。

2 个答案:

答案 0 :(得分:2)

尝试使用此方法对已更改的母版重新定位:

# Add the original remote, e.g. "upstream":
git remote add upstream https://github.com/whoever/whatever.git
# Fetch all the branches of that remote into remote-tracking branches,
# such as upstream/master:
git fetch upstream
# Make sure that you're on your intended branch, e.g. master:
git checkout master
# Rewrite your branch so that any commits of yours that
# aren't already in upstream/master are replayed on top of that branch:
git rebase upstream/master
# resolve any merge conflicts
# push the end result
git push origin master

答案 1 :(得分:0)

似乎是执行pull --rebase而不仅仅是git pull MainRepo master的结果 你应该阅读Git rebase 这是一个Git Cheatsheet

这些步骤足以满足您尝试完成的工作流程:

当您准备好拉动并推动您的更改时 git pull origin master

解决任何冲突后 git commit -m "commit message" files

git push (or git push -u origin/your-branch)