jesseduffield / lazygit

simple terminal UI for git commands
MIT License
48.13k stars 1.73k forks source link

Update tracking behaviour for branches created from remote branches #3712

Closed part22 closed 3 days ago

part22 commented 5 days ago

Overview

Current Behaviour New Behaviour
Local branches will always track the remote branches they were created from. Local branches will track the remote branches they were created from only if their names match.

Description

The current behaviour when creating a new branch off of a remote branch is to always track the branch it was created from.

For example, if a branch 'my_branch' is created off of the remote branch 'fix_crash_13', then 'my_branch' will be tracking the remote 'fix_crash_13' branch. It is common practice to have both the local and remote branches named the same when the local is tracking the remote one. Therefore, it is reasonable to expect that 'my_branch' should not track the remote 'fix_crash_13' branch.

The new behaviour when creating a new branch off of a remote branch is to track the branch it was created from only if the branch names match. If the branch names DO NOT match then the newly created branch will not track the remote branch it was created from.

For example, if a user creates a new branch 'fix_crash_13' off of the remote branch 'fix_crash_13', then the local 'fix_crash_13' branch will track the remote 'fix_crash_13' branch. However, if the user creates a new branch called 'other_branch_name' off of the remote branch 'fix_crash_13', then the local 'other_branch_name' branch will NOT track the remote 'fix_crash_13' branch.

stefanhaller commented 5 days ago

Before I start reviewing this: do we actually need it? In #3675 my suggestion was to never set up tracking when pressing n, letting people use space (or press c in the local branches panel to checkout by name) if they do want a tracking branch. Jesse agreed. This is much simpler, so I prefer that solution.

I'm not too worried about the added code complexity, but I am concerned about adding config options that we don't absolutely need. We have so many options already, it just makes it harder to find the really important ones among them.

part22 commented 5 days ago

I could just disable the tracking when using the n keybinding but I think it's always tricky to remove something people might have got used to. But you and Jesse know the software and the codebase better than I do, so I will defer to your good judgement! 😉

stefanhaller commented 5 days ago

You mean people who are used to pressing n enter to create a tracking branch? How about we keep your logic of setting the tracking branch only if the name matches, but not if it doesn't? This should cover that case but also address the problem raised in #3675. Just without the configurability. What do you think?

part22 commented 5 days ago

That seems like a good compromise but if you feel that is still too much added complexity I am fine with just disabling the tracking when using n on remote branches.

stefanhaller commented 5 days ago

No, I like this middle-ground version best. It's just so unlikely that someone wants to create a branch that has the same name but does not track the remote. As I said, the added code complexity doesn't bother me so much.

part22 commented 5 days ago

I have removed the configuration part and kept the new behaviour part.

Recap

Current Behaviour New Behaviour
Local branches will always track the remote branches they were created from. Local branches will track the remote branches they were created from only if their names match.
part22 commented 3 days ago

Oh, and it would be good to update the PR description, because it will end up in the merge commit message.

I have updated it.

stk-ableton commented 3 days ago

Thanks! Very happy with the current state. Merging.

stefanhaller commented 3 days ago

(Grr, I keep commenting with the wrong account. That was me. 😄)