title: How to resolve git conflicts on branch without merging or rebasing
body: <p>My usual feature/bug branch workflow is like this:</p>
  
  <ul>
  <li>Branch</li>
  <li>Make changes</li>
  <li>Rebase to master</li>
  <li>Push and make github pull request (PR)</li>
  <li>Make more changes</li>
  <li>Somebody else reviews code and clicks the github merge button</li>
  </ul>
  
  <p>Let's assume the merge button on the PR can't be clicked because my feature branch now has conflicts with master.  At this point I typically want to resolve the conflicts with master, and I want to do that <em>on my feature branch</em> so that I can have the person who is reviewing my code see:</p>
  
  <ol>
  <li>A nice diff that doesn't have merge commits and/or random changes from master</li>
  <li>My conflict resolutions</li>
  <li>A merge button they can click</li>
  </ol>
  
  <p>However, I may not want to rebase because code review is in progress already (sometimes I rebase anyway, but other times I want to avoid it).</p>
  
  <p>How can I reliably and efficiently use git to achieve that?</p>
  
  <p>What I currently do is a mixture of these things:</p>
  
  <ul>
  <li>"Just knowing" what needs cherry picking or changing to resolve the conflict (sometimes...)</li>
  <li>Trial merges (<code>git merge master</code>; (see which file has conflicts, then git annotate to find relevant commit); <code>git reset --hard origin/my-feature-branch</code>; <code>git cherry-pick &lt;some commit&gt;</code> (or maybe make some change by hand); (repeat)) </li>
  </ul>
  
  <p><s>Sometimes that doesn't work because the conflicts are empty, so I don't know what to annotate to find the right commit.</s>  Edit: in fact in the empty-conflict case I imagine it's not possible to resolve without merge or rebase (but it is possible in other cases -- see example below).</p>
  
  <p>When it does work, it seems like it's a lot of work that git might be able to help me do in a more automated way.</p>
  
  <p>I've tried <code>git-imerge</code> also -- that doesn't seem designed exactly for this purpose, and it also exited with an unhandled exception.</p>
  
  <p>Here is a concrete working example, since there is skepticism in answers here that it is sometimes possible to resolve conflicts on a branch as I describe here without merging or rebasing (note this doesn't show every step of the workflow above, and demonstrates only the 'resolve conflicts on branch without merge or rebase' part):</p>
  
  <pre><code>$ mkdir -p conflict-example/upstream
  $ cd conflict-example/upstream
  $ git init .
  Initialised empty Git repository in /tmp/conflict-example/upstream/.git/
  $ echo 'changed_only_upstream before' &gt; changed_only_upstream
  $ echo 'changed_only_downstream before' &gt; changed_only_downstream
  $ echo 'changed_in_both before' &gt; changed_in_both
  $ git add .
  $ git commit -m 'initial'
  [master (root-commit) 23040ea] initial
   3 files changed, 3 insertions(+)
   create mode 100644 changed_in_both
   create mode 100644 changed_only_downstream
   create mode 100644 changed_only_upstream
  $ cd ..
  $ git clone upstream downstream
  Cloning into 'downstream'...
  done.
  $ cd downstream
  $ git checkout -b downstream
  Switched to a new branch 'downstream'
  $ vim changed_in_both
  $ vim changed_only_downstream
  $ cat changed_in_both
  changed_in_both before
  downstream
  $ cat changed_only_downstream
  changed_only_downstream before
  downstream
  $ git commit -am 'downstream'
  [downstream 6ead47f] downstream
   2 files changed, 2 insertions(+)
  $ cd ../upstream
  $ vim changed_in_both
  $ vim changed_only_upstream
  $ cat changed_in_both
  changed_in_both before
  upstream
  $ cat changed_only_upstream
  changed_only_upstream before
  upstream
  $ git commit -m 'upstream conflict' changed_in_both
  [master e9ec7c5] upstream conflict
   1 file changed, 1 insertion(+)
  $ git commit -m 'upstream non-conflict' changed_only_upstream
  [master d4057e0] upstream non-conflict
   1 file changed, 1 insertion(+)
  $ cd ../downstream/
  $ git checkout master
  Switched to branch 'master'
  Your branch is up-to-date with 'origin/master'.
  $ git pull
  remote: Counting objects: 6, done.
  remote: Compressing objects: 100% (4/4), done.
  remote: Total 6 (delta 2), reused 0 (delta 0)
  Unpacking objects: 100% (6/6), done.
  From /tmp/conflict-example/upstream
     23040ea..d4057e0  master     -&gt; origin/master
  Updating 23040ea..d4057e0
  Fast-forward
   changed_in_both       | 1 +
   changed_only_upstream | 1 +
   2 files changed, 2 insertions(+)
  $ git checkout downstream
  Switched to branch 'downstream'
  $ git merge master
  Auto-merging changed_in_both
  CONFLICT (content): Merge conflict in changed_in_both
  Recorded preimage for 'changed_in_both'
  Automatic merge failed; fix conflicts and then commit the result.
  $ git merge --abort
  $ git log --all --graph --pretty=oneline --abbrev-commit --decorate
  * d4057e0 (origin/master, origin/HEAD, master) upstream non-conflict
  * e9ec7c5 upstream conflict
  | * 6ead47f (HEAD -&gt; downstream) downstream
  |/
  * 23040ea initial
  $ git cherry-pick e9ec7c5
  error: could not apply e9ec7c5... upstream conflict
  hint: after resolving the conflicts, mark the corrected paths
  hint: with 'git add &lt;paths&gt;' or 'git rm &lt;paths&gt;'
  hint: and commit the result with 'git commit'
  $ vim changed_in_both
  $ cat changed_in_both
  changed_in_both before
  upstream
  $ git add changed_in_both
  $ git commit
  Recorded resolution for 'changed_in_both'.
  [downstream 7a4f7a7] upstream conflict
   Date: Sat Aug 27 14:41:13 2016 +0100
   1 file changed, 1 insertion(+), 1 deletion(-)
  $ git log --all --graph --pretty=oneline --abbrev-commit --decorate
  * 7a4f7a7 (HEAD -&gt; downstream) upstream conflict
  * 6ead47f downstream
  | * d4057e0 (origin/master, origin/HEAD, master) upstream non-conflict
  | * e9ec7c5 upstream conflict
  |/
  * 23040ea initial
  $ git checkout master
  Switched to branch 'master'
  Your branch is up-to-date with 'origin/master'.
  $ git merge downstream
  Merge made by the 'recursive' strategy.
   changed_only_downstream | 1 +
   1 file changed, 1 insertion(+)
  $ git log --all --graph --pretty=oneline --abbrev-commit --decorate
  *   c036d60 (HEAD -&gt; master) Merge branch 'downstream'
  |\
  | * 7a4f7a7 (downstream) upstream conflict
  | * 6ead47f downstream
  * | d4057e0 (origin/master, origin/HEAD) upstream non-conflict
  * | e9ec7c5 upstream conflict
  |/
  * 23040ea initial
  </code></pre>
  
  <p>I believe if I had chosen a different resolution in the cherry-pick, I wouldn't have been able to merge using that merge command (which is at least similar to what github merge button does).  In those situations, typically I either do the merge myself or rebase -- but that is not what this question is about (though if there's some way to achieve merge button-clickability without merging master or rebasing in those situations too it'd be interesting to hear about!).</p>