简体   繁体   English

将提交推送到派生存储库的分支

[英]Pushing a commit to a branch of a forked repository

I am getting a strange error when updating a forked repository. 更新分叉的存储库时出现奇怪的错误。 I already created a dev-branch in the forked repo(for my development work). 我已经在派生仓库中创建了一个开发分支(用于我的开发工作)。

  1. I have cloned a forked repo 我已经克隆了一个分叉的仓库

      git clone https://github.com/twbs/bootstrap 
  2. Check the current branch 检查当前分支

      git branch *master dev-branch 
  3. Change to dev-branch 转到开发分支

     git checkout dev-branch 
  4. make changes and commited them to dev-branch 进行更改并将其提交给开发部门

      git commit 
  5. Add remote url 添加远程URL

      git remote add parent git@github.com:twbs/bootstrap 
  6. when i do a git push now, i am getting error hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart 当我现在执行git push时,出现错误提示:更新被拒绝,因为您当前分支的提示位于提示后面:远程对应

  7. So, I did 所以我做了

      git fetch parent git merge parent/master A new commit screen is opened with commit message "Merge remote-tracking branch 'bootstrap/master' into dev-branch" 
  8. Still i get the same error, when I do git push 当我执行git push时,我仍然遇到相同的错误

  9. Now, I did 现在,我做到了

      git pull A new commit screen is opened with commit message "Merge branch 'dev-branch' of https://github.com/username/bootsrap into dev-branch 
    1. Now, git push worked. 现在,git push起作用了。

I don't know what has happened. 我不知道发生了什么 Did i make a mistake somewhere ? 我在某处犯错了吗? Can someone point out to me the right steps to update and push from a different branch of forked repository ? 有人可以向我指出从分叉存储库的另一个分支进行更新和推送的正确步骤吗?

What version of git are you using? 您正在使用什么版本的git? Older versions of Git used to default to "attempt to push all local branches to the remote", which is what it appears yours tried to do. Git的较旧版本默认情况下默认为“尝试将所有本地分支推送到远程”,这似乎是您尝试这样做的。

Newer versions of Git default to only attempting to push the currently checked out branch to a branch of the same name upstream (which I also dislike). 较新版本的Git默认只尝试将当前签出的分支推到上游具有相同名称的分支(我也不喜欢)。 I personally recommend git config --global push.default tracking (or upstream in newer versions), which attempts to push your current branch to its upstream. 我个人建议使用git config --global push.default tracking (或在较新版本中为上游),它会尝试将当前分支推送到其上游。

In your case, you had two branches, and it tried to push them both. 在您的情况下,您有两个分支,它试图将它们都推入。 Both were rejected because both were behind. 两者均被拒绝,因为两者均落后。

So no mistake on your part really, although if you prefer a linear history you might want to consider rebase instead of merge. 因此,即使您偏爱线性历史记录,您也可以考虑重新设置基准,而不是合并,这确实是没有错的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM