Вопрос

We have a shared git repository that everybody uses and we have two branches

  • master
  • dev

I have my own fork of this repo. I pull changes from the upstream repo from time to time into the respective branches in the fork and then rebase my feature branches onto dev.

ie.

fork

  • master
  • dev
  • feature1

Commands:

git checkout dev
git pull upstream dev
git checkout feature1
git rebase dev

Now from time to time when I go to push my feature1 branch back to my fork I get told my branch is out of date and to do a pull and then I get merge conflicts.

I am and will be the only person working off this fork/branch so I'm confused as to why I'm getting these merge conflicts.

Is it an issue with rebasing a pushed branch even though no one else is working off it? What is a way to workaround this or a better workflow to follow

Это было полезно?

Решение

This happens because you're rebasing your changes. Once you've done that your branch no longer contains the same commits as it did before, it contains new commits that reflect the same (or similar changes). When you try to push those changes, git notices that the commit at the current tip of the branch on the target repository isn't an ancestor of the commit which you're trying to set as the new tip of that branch.

You need to use git push -f to force the push to happen even though it isn't a fast forward. But you when doing this you need to be careful that you're not erasing other changes from that branch. If that branch is only ever modified in your single repository, it should be alright to use -f on that one branch, but you'll definitely want to be careful to not push to the master or dev branch using that flag.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top