I have implemented the classic OSS git support / contributor workflow for a company project on github, however in one edge case there are some strange results that I'm not sure how to get around.
Suppose there is a typical project that I forked and added upstream to keep it up to date.
git clone git@github.com:kozhevnikov/<project>.git git remote add upstream git@github.com:<company>/<project>.git
For the purposes of this example, this fork is behind several commits.
git reset --hard HEAD~5 && git push --force
I am working on this fork and pushing some commits before pushing the last commit and creating a transfer request. I am updating my fork clone to make sure there are no conflicts.
touch foo && git add foo && git commit -m foo && git push touch bar && git add bar && git commit -m bar git pull
Now, when I try to press on my fork, I get a deviation.
git push To git@github.com:kozhevnikov/<project>.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@github.com:kozhevnikov/<project>.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (eg 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.
What should I do next? All I want is that the transfer request contains foo and bar, but ...
When I pull , the pull request contains duplicates of foo, as well as an additional merge.
git pull Merge made by the 'recursive' strategy. git push
In a github request, pull looks like this.
Showing 4 unique commits by 1 author. 12345 kozhevnikov foo 4 minutes ago 67890 kozhevnikov foo 4 minutes ago abcde kozhevnikov bar 2 minutes ago fghij kozhevnikov Merge branch 'master' of github.com:kozhevnikov/<project> just now
When I git pull --rebase instead of pull , at best it will include other people in my transfer request (those from reset), and at worst it gives me merge conflicts.
When I git push --force without any pull or --rebase , it works fine, however itβs very difficult for me to say that everyone uses force or makes it part of the standard workflow, because I can imagine that few or a small subtopic working on one fork and stepping on each other, with a forced push.
Any ideas? What am I missing?