wfxr / forgit

:zzz: A utility tool powered by fzf for using git interactively.
MIT License
4.33k stars 136 forks source link

Add ability to checkout existing branch with gcb #232

Closed cjappl closed 1 year ago

cjappl commented 1 year ago

Part two of the original #231

It would be nice to add this functionality to bash/zsh @wfxr or @carlfriedrich if you have time :)

Going to merge this basically straight away, as I see it being a huge gain to my personal workflow!

carlfriedrich commented 1 year ago

@cjappl I don't understand what this patch actually does. Wasn't it possible before to checkout existing branches?

cjappl commented 1 year ago

At least in fish the previous behavior if you “gcb main” (where main existed before) was an error:

fatal: a branch named 'main' already exists

This may work in zsh/bash, I’m not sure, but it hadn’t worked in fish until this pr!

This new logic in psuedocode is:

if an argument is provided:
    if argument in list of branches:
        check out that argument as existing branch
    else
        create new branch with that name, and check it out

Where as before it was:

If an argument is provided to gcb
    Create and check out that branch

That create would fail if the branch already existed.

Does that make sense? It’s totally possible I missed something here.

Also apologies if the formatting ended up whacky, doing this on my phone at 5AM! 😀

On Wed, Aug 17, 2022 at 12:16 AM, Tim @.***> wrote:

@.***(https://github.com/cjappl) I don't understand what this patch actually does. Wasn't it possible before to checkout existing branches?