mcasper / git-clean

A Command Line Tool written in Rust for cleaning up local and remote Git branches
MIT License
54 stars 9 forks source link

Why delete local branches that haven't been pushed? #32

Closed dam5h closed 1 year ago

dam5h commented 1 year ago

I loved this tool for the first several usages. Then I recently ran into an issue where I accidentally lost some work since it was suggested to be deleted based on not being on the remote. I did not see the local only branch in the list to be deleted at the time.

The code here does this https://github.com/mcasper/git-clean/blob/c0f7369199c3e9fc7e0dc0f68587d75728925d46/src/branches.rs#L95

I still think this is a great tool, just don't understand this choice. Sometimes I have work that I consider valuable but it is not pushed up to the remote yet.

Thankfully I was able to recover the commit via the reflog. It may be worth a note that users should push any local work up to remote to avoid losing it.

Cheers and thank you for this tool! Dave

mcasper commented 1 year ago

Hey @dam5h, I'm so sorry for the trouble! Glad you were able to get the commits back.

This tool is only intended to delete branches that don't have any commits ahead of your main branch, local-only or otherwise. If it did something else, that's a bug!

dam5h commented 1 year ago

I think it'd be a bug then. My branch had code that was not in main. Now it may not have been recently rebased onto main but it definitely was "ahead" in the fact that it had a sub-crate in the rust workspace that was not in main in any way.

The code linked above seems to add any local-only branch to branches vector, without checking anything else.

Cheers, Dave

tpilewicz commented 1 year ago

Hello, same issue here. IMO this is problematic as it lets you delete a branch that is ahead of main.

The value of git-clean is a bit diminished if you have to check carefully that you pushed all your branches before running it 😕

tpilewicz commented 1 year ago

@mcasper WDYT of an option to disable this behavior? I understand it's here to take shortcuts and speed up the checks on branches, but I figure most users would want to run the command without the risk of deleting a branch that just wasn't pushed?

I can open a PR if you want

mcasper commented 1 year ago

@tpilewicz That's fine with me, happy to review a PR!

mcasper commented 1 year ago

Released in 0.8.0!