Skip to content

When creating a new branch off of a main branch that is behind its upstream, use the upstream instead #4490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stefanhaller
Copy link
Collaborator

  • PR Description

Very often my local main branch is behind its upstream, because I have no reason to keep it up to date. In the olden days it used to be necessary to keep it up to date in order to rebase feature branches onto it, so you'd have to press f on it occasionally before pressing r. This is no longer necessary now that we have the "rebase onto base branch" command (r b).

The only time I now need an up-to-date local main is when I want to create a new branch off of it. This is annoying, because I have to press f and wait for it to complete before I can create a new branch; but I know that origin/main is probably up to date (or close to up to date), because lazygit fetches it in the background all the time. So why can't I just create my new branch off of origin/main, then? (Sure, I could switch over to the Remotes tab, open origin, and select origin/main there, but that's cumbersome.)

So this is exactly what this PR does: if the local main is strictly behind its upstream (as opposed to diverged, which should be very rare for a main branch), then when pressing n on it we create the new branch off of origin/main.

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

…stream, use the upstream instead

Very often my local main branch is behind its upstream, because I have no reason
to keep it up to date. In the olden days it used to be necessary to keep it up
to date in order to rebase feature branches onto it, so you'd have to press `f`
on it occasionally before pressing `r`. This is no longer necessary now that we
have the "rebase onto base branch" command (`r b`).

The only time I now need an up-to-date local main is when I want to create a new
branch off of it. This is annoying, because I have to press `f` and wait for it
to complete before I can create a new branch; but I know that origin/main is
probably up to date (or close to up to date), because lazygit fetches it in the
background all the time. So why can't I just create my new branch off of
origin/main, then? (Sure, I could switch over to the Remotes tab, open origin,
and select origin/main there, but that's cumbersome.)

So this is exactly what this commit does: if the local main is strictly behind
its upstream (as opposed to diverged, which should be very rare), then when
pressing `n` on it we create the new branch off of origin/main.
@stefanhaller stefanhaller added the enhancement New feature or request label Apr 16, 2025
Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 5f809801 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (5f80980) Report Missing Report Missing Report Missing
Head commit (cccd5f9) 54488 47261 86.74%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4490) 39 39 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@stefanhaller
Copy link
Collaborator Author

Keeping as draft for now because I'm unsure if it needs to be configurable.

Personally I'm happy with this behavior being unconditional; I'm sure I always want it this way. But I'm not sure if some people might find it surprising. We could add a user config along the lines of git.newBranchOffMainBranch: ask|useUpstream|useLocal; the default would have to be "useLocal" if we want to avoid a breaking change, but it could be "ask" if we want people to learn about it. We'd then show a menu with the two options, and an explanatory text how to get rid of the menu by setting the right option in the config. @jesseduffield Let me know what you think!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant