Note that there are some explanatory texts on larger screens.

plurals
  1. POgit pull --rebase upstream & git push origin rejects non-fast-forward?
    text
    copied!<p>I've implemented classic OSS maintainer/contributor git workflow for a company project on github, however one edge case produces some weird results that I'm not sure how to get around.</p> <p>Lets say there is a typical project that I forked and added upstream remote to keep it up to date.</p> <pre><code>git clone git@github.com:kozhevnikov/&lt;project&gt;.git git remote add upstream git@github.com:&lt;company&gt;/&lt;project&gt;.git </code></pre> <p>For the purposes of this example this fork is behind by a few commits.</p> <pre><code>git reset --hard HEAD~5 &amp;&amp; git push --force </code></pre> <p>I work on this fork and push some commits, before pushing my last commit and creating a pull request I update my fork's clone to make sure there are no conflicts.</p> <pre><code>touch foo &amp;&amp; git add foo &amp;&amp; git commit -m foo &amp;&amp; git push touch bar &amp;&amp; git add bar &amp;&amp; git commit -m bar git pull --rebase upstream master From github.com:&lt;company&gt;/&lt;project&gt; * branch master -&gt; FETCH_HEAD First, rewinding head to replay your work on top of it... Applying: foo Applying: bar </code></pre> <p>Now, when I try to push to my fork I get rejected.</p> <pre><code>git push To git@github.com:kozhevnikov/&lt;project&gt;.git ! [rejected] master -&gt; master (non-fast-forward) error: failed to push some refs to 'git@github.com:kozhevnikov/&lt;project&gt;.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details. </code></pre> <p>What should I do next? All I want is for the pull request to contain foo and bar commits, however...</p> <p>When I <code>pull</code>, pull request contains duplicate foo commits as well as extra merge one.</p> <pre><code>git pull Merge made by the 'recursive' strategy. git push </code></pre> <p>On github pull request looks like this.</p> <pre><code>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/&lt;project&gt; just now </code></pre> <p>When I <code>git pull --rebase</code> instead of <code>pull</code>, at best it'll include other people's commits into my pull request (those from reset), and at worst it gives me merge conflicts.</p> <p>When I <code>git push --force</code> without any <code>pull</code> or <code>--rebase</code> it works perfectly, however I'm very uneasy in saying to everyone use the force or making it part of standard workflow as I can imagine few people or a small subteam collaborating on a single fork and stepping on each other's toes with forced push.</p> <p>Any ideas? What am I missing?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload