+3

Log, Checkout: trying to check out remote branch with behind tracking branch should offer fast-forward merge

Bernard 3 years ago updated by Maja Stamenic 2 years ago 4

Example: current branch is branch1; want to checkout 'develop' but develop diverged and requires a pull (an extra step).

The idea is using an existing local branch that is already tracking it, not create a new local branch. (I do not want to checkout as "develop2" just because develop has diverged!)

Use cases:
- Submodules: Over time submodules can be changed (added/removed). This is not an operation that is well done when performing a checkout and submodules directories gets in the way when switching back & forth in history.
- PR workflow : PR systems often merges a PR branch to develop/master, locally switching from a PR branch that just got merged by such system to the latest "develop" would often yield near-zero change and would be more "friendly" with system that looks for changes on disk to "reload" pages and such.

- Optimization; large repo with long history:  switching to a branch that has diverged for a long time on a large repo can be very slow (because of the large number of files to change). Git needs to restore a very old state. In the case that the pull step would presumable restore the branch to a fairly recent state, then we could have saved us the heavy back&forth in history. From a Git standpoint, we could have saved lot of time by going directly to the other commit without going through a very old commit first.

Currently this case is already detected in SmartGit and a dialog with a few options are shown to the user. I think we could safely add another option.

I am not sure what you mean, but in the attached picture, SmartGit says "Local branch 'develop' is diverged from checkout target 'origin/develop' -- this does not seem to match what you are talking. (correct me if I am wrong). There are no commits on local develop. In this case, a git pull on 'develop' would immediately jump to 'origin/develop'.  

- If you mean uncommitted changes, then yes, in that case it might not be good. Although I don't know why we couldn't simply go into the standard Stash/Apply dance.
- If you mean a local commit on 'develop' that has not been pushed to 'origin', then I understand you would need a re-base of some sort or it's gone. I believe we can detect this case and simply not allow to perform this "direct" operation.

In the picture, I right-clicked the "origin/develop" yellow branch and did "Checkout". You can see I was on another branch. I think SmartGit can easily detect if it is safe and perform a checkout without loosing anything. I certainly do not want to create a local branch "develop-2".  

I also understand that there could be multiple local branches tracking the selected target, well, this is why you would have a branch selector similar to the one that is already present but only showing branches that are tracking the target.

I am not a git command line wiz, but I suspect it might not be obvious to implement this without being absolutely certain that there is no possibility of loosing something because maybe the origin diverged wildly differently while the operation is executing.




Sorry, I misunderstood you. The incorrectly named "diverged"-warning will be changed to a "behind checkout target" message.

I've changed the request's title so I better understand what I think is requested.

Awesome, good idea to change the title. Yes, I believe you got it right.  I hope it still conveys the idea that the checkout and fast-forward merge operations to be done as a single "step" (from the files standpoint at least) else it's pretty much pointless other than saving a few mouse clicks.

I just discovered that I could run the custom tool "ff-merge.sh" from the context menu and it appear to achieve roughly what I want just not great UX there. I can run this tool and no changes are performed on the working directory until I do a separate checkout 'develop'.

Integrating this special fast-forward merge for a more powerful checkout is where a tool like SmartGit can shine: Higher-level operations made easier, no need to know in advance that this is actually called a "fast forward merge". (not feeling like you are merging anything here).

Maybe just adding an option in popup Checkout&Pull so we have it in one step.