I found git examples with fzf(fuzzy finder) and they does work great. like:
# fbr - checkout git branch
fbr() {
local branches branch
branches=$(git branch -vv) &&
branch=$(echo "$branches" | fzf +m) &&
git checkout $(echo "$branch" | awk '{print $1}' | sed "s/.* //")
}
# fbr - checkout git branch (including remote branches)
fbr() {
local branches branch
branches=$(git branch --all | grep -v HEAD) &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}
I have this in my .bashrc
bind '"\C-b": "fbr \n"'
After I press Ctrl-b I get to choose a git's branch and it switches right after I press enter, but is there a way to type something first like git push staging
(and then get the list of branches and put selected branch right where the cursor was before calling the list of branches, and then I press enter to push the selected branch to staging
)
Ex:
git push staging
(Ctrl-b - choose a branch) and I want to get this output - git push staging selected_branch