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
To view your remote branches, simply pass the -r flag to the git branch command. You can inspect remote branches with the usual git checkout and git log commands. If you approve the changes a remote branch contains, you can merge it into a local branch with a normal git merge .
just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.
1 Answer. git fetch --all and git pull -all will only track the remote branches and track local branches that track remote branches respectively. Run this command only if there are remote branches on the server which are untracked by your local branches. Thus, you can fetch all git branches.
If you're using Windows, try git checkout @(git branch -a | fzf).trim()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With