Skip to content

allow user to "force push with lease" after performing rebase in the app #6913

Closed

Description

@shiftkey

Please describe the problem you think should be solved

With #6698 Desktop will now detect rebase conflicts and guide the user to resolve them. If the user gets to the end of the rebase, they will potentially have a rewritten history that they need to push, that clashes with what exists on the remote.

Here's an example:

  1. I have two branches (lg is just an alias):
$ git lg 2-simple-rebase-conflict-base-branch                                                                                              * 191dbf5 - (origin/2-simple-rebase-conflict-base-branch, 2-simple-rebase-conflict-base-branch) them bullet points tho (2 weeks ago) <Brendan Forster>
* 24b8b8a - add command line instruction (2 weeks ago) <Brendan Forster>
* 7eb4682 - added MIT license to project (2 weeks ago) <Brendan Forster>
* ad6f94b - add more notes to README (2 weeks ago) <Brendan Forster>
* d49f163 - added README (2 weeks ago) <Brendan Forster>
* dda2600 - Create README.md (2 weeks ago) <Brendan Forster>
* ebe86c6 - Initial commit (2 weeks ago) <Brendan Forster>

$ git lg 2-simple-rebase-conflict-target-branch                                                                                            
* abdbae0 - (HEAD -> 2-simple-rebase-conflict-target-branch, origin/2-simple-rebase-conflict-target-branch) add MPL license to repository (2 weeks ago) <Brendan Forster>
* dda2600 - Create README.md (2 weeks ago) <Brendan Forster>
* ebe86c6 - Initial commit (2 weeks ago) <Brendan Forster>

I want to rebase 2-simple-rebase-conflict-target-branch on top of 2-simple-rebase-conflict-base-branch, which means this commit needs to be rebased:

* abdbae0 - (HEAD -> 2-simple-rebase-conflict-target-branch, origin/2-simple-rebase-conflict-target-branch) add MPL license to repository (2 weeks ago) <Brendan Forster>

Note that this commit exists on the remote as well as the local repository. The git pull --rebase issue we're tracking in #6549 should only affect local commits, which makes me think we might be able to skip this for 1.6.3. @billygriffin let me dig into this a bit more and report back regarding the urgency.

After performing the rebase, this is what my history looks like for 2-simple-rebase-conflict-target-branch:

$  git lg 2-simple-rebase-conflict-target-branch                                                                                          ±
* 59a9184 - (HEAD -> 2-simple-rebase-conflict-target-branch) add MPL license to repository (11 seconds ago) <Brendan Forster>
* 191dbf5 - (origin/2-simple-rebase-conflict-base-branch, 2-simple-rebase-conflict-base-branch) them bullet points tho (2 weeks ago) <Brendan Forster>
* 24b8b8a - add command line instruction (2 weeks ago) <Brendan Forster>
* 7eb4682 - added MIT license to project (2 weeks ago) <Brendan Forster>
* ad6f94b - add more notes to README (2 weeks ago) <Brendan Forster>
* d49f163 - added README (2 weeks ago) <Brendan Forster>
* dda2600 - Create README.md (2 weeks ago) <Brendan Forster>
* ebe86c6 - Initial commit (2 weeks ago) <Brendan Forster>

You'll see the commit has a different ID now:

* 59a9184 - (HEAD -> 2-simple-rebase-conflict-target-branch) add MPL license to repository (11 seconds ago) <Brendan Forster>

“When I run into a merge conflict, I don’t know where to go to resolve it. Anyone who works off of multiple branches will likely run into this problem at least occasionally.”

Now, when I switch to Desktop I see this in the header:

screen shot 2019-02-21 at 2 56 19 pm

If I were to press pull again it tries to do the rebase again and leads to more confusion.

[Optional] Do you have any potential solutions in mind?

We need to track these two things in app state:

  • GitHub Desktop detected and resolved a rebase on behalf of the user
  • The history needs to be force-pushed to get the users changes back to the remote repository

The tentative flow we're going with is outlined in this GIF from #5953 (comment):

Activity

  1. added this to the 1.6.3 milestone on Feb 21, 2019
  2. shiftkey commented on Feb 21, 2019

    @shiftkey
    MemberAuthor

    Yep, so in response to this:

    The git pull --rebase issue we're tracking in #6549 should only affect local commits, which makes me think we might be able to skip this for 1.6.3.

    I think we can defer this to 1.7.0 and whenever we tackle #6551. Here's an interactive example built upon #6893 to walk through my reasoning behind this:

    • I make a commit to this repository on GitHub so the branch is ahead, but the user doesn't see it until it's too late

    • I make a commit locally and the button indicates it's good to push (note the order of commits, we'll come back to that at the end):

    • This triggers the "push needs pull" error, and the app gets the latest changes:

    • Now we have some better context (and the app sees that "with rebase" is going to happen)

    • We pull --rebase and that completes without error. You'll see the Create DOOOT.md commit is inserted before the local commit in the history - that's the "rebase local commits on top of remote commits" step that the flow enables:

    Let me know if you have any questions or are in violent disagreement about moving this to 1.7.0 given the above flow...

  3. billygriffin commented on Feb 21, 2019

    @billygriffin
    Contributor

    Discussed with @shiftkey, and our hypothesis here is that for the tightly scoped pull --rebase flow that we're enabling in 1.6.3, we don't anticipate that there will be a scenario requiring a force push, so unless we uncover that that assumption is faulty, we're punting on enabling force push as part of rebasing until the broader rebase flow currently intended for 1.7.

  4. modified the milestones: 1.6.3, 1.7.0 on Feb 21, 2019
  5. shiftkey commented on Feb 27, 2019

    @shiftkey
    MemberAuthor

    Pondering on how this will work in the app, and I think I've settled on the flow I want to "enable" this behaviour in the app. When a rebase is completed successfully in Desktop, the app should update its state to track the rebased branch and the updated SHA of the rebased branch.

    This could be as simple as something in IBranchesState:

      // branches that may be force-pushed to the remote in the app,
      // keyed by their local branch name and containing the commit ID
      // after rebase, to ensure no external tools have changed the branch
      // commits unexpectedly 
      readonly rebasedBranches: ReadonlyMap<string, string>

    By tracking this information in app state (it won't persist between restarts without having some sort of backing store, but I think that's fine for v1) we can ensure we only enable --force-with-lease for branches that Desktop has touched.

    When rendering the push/pull button and ahead/behind commits are detected, we can change the behaviour shown if the current branch is listed in this map and the current tip of the branch matches the rebased SHA.

    After the branch has been pushed with --force-with-lease the branch is removed from this list.

  6. added
    accessibility
    and removed
    accessibility
    on Feb 27, 2019
  7. self-assigned this
    on Feb 28, 2019
  8. tgpsantos commented on Sep 22, 2020

    @tgpsantos

    I've recently learned that push --force-with-lease is advised against push --force, at least in most use cases.

    I use GitHub Desktop for basically everything I need - including rebases - so two questions popped in my mind:
    1: push --force-with-lease was enabled in #6981, but when you mean "enable" you mean that users can use command line for that purpose (after rebase and before force push) or is there an option inside Github Desktop?
    2: If push --force-with-lease is actually a better practice than push --force, shouldn't the force push be set to force with lease by default? Again, this might be an overstatement so I apologize in advance, as I'm only basing this thought on what I've read in a couple of articles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions