Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a git's branch with fuzzy finder?

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

like image 682
whitesiroi Avatar asked Apr 09 '16 06:04

whitesiroi


People also ask

How do I find remote branches?

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 .

How do I fetch development branch?

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.

How do I fetch all branches?

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.


1 Answers

If you're using Windows, try git checkout @(git branch -a | fzf).trim()

like image 70
legendmohe Avatar answered Oct 02 '22 21:10

legendmohe