Skip to content
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

Change default force push strategy #4077

Open
ahmafi opened this issue Nov 25, 2024 · 2 comments
Open

Change default force push strategy #4077

ahmafi opened this issue Nov 25, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@ahmafi
Copy link

ahmafi commented Nov 25, 2024

Is your feature request related to a problem? Please describe.
I usually work on a branch and I do a lot of commits with --amend or changing the order of commits or editing previous commits, which leads to requiring a force push. Usually I'm the only one who works on that branch, but sometimes my teammates do a single commit on that branch, which we might forget to talk about. As I usually force push a lot, I don't look at fetch status of how many commits are changed on the remote and I might force push their changes.
Outside lazy git people usually use git push --force-with-lease which helps with this. Then they fetch and read the changes, and they can force push again. But in lazygit as it automatically fetches in the background, the --force-with-lease becomes useless, and it behaves like --force when a fetch has happened.

Describe the solution you'd like
Use git push --force-with-lease --force-if-includes as default, and it won't force push other people changes. Also add another commit without --force-if-include for other situations that we actually want to ignore other remote commits. Or ask in another dialog if we want to ignore their changes.

I think it's also a safer option, as lazygit fetches periodically by itself (and git don't).

@ahmafi ahmafi added the enhancement New feature or request label Nov 25, 2024
@stefanhaller
Copy link
Collaborator

This has been discussed several times here in the past, most recently 3 days ago. See #4068 (reply in thread) for a brief summary.

In short: you get the behavior you want by doing git config --global push.useForceIfIncludes true.

@ahmafi
Copy link
Author

ahmafi commented Nov 25, 2024

Oh great, sorry, completely forget to search in previous issues.
I think this issue is not going to stop repeating in GitHub issues because the combination of auto fetching and --force-with-lease makes things weird. At first, I didn't expect to force push on my teammate commits because I could see in the bottom right side of lazygit that it's using --force-with-lease and I didn't notice the auto fetch.

Maybe adding a more comprehensive message in the force push warning dialog would be helpful? Or suggest people to turn on this global option somewhere?

Another thing is that I might not always want to have that global config. Tool level (lazygit) configuration for this can be beneficial.

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

No branches or pull requests

2 participants