From b1ba713659139ae1ec8c00fc1c00a4e5d0ef029f Mon Sep 17 00:00:00 2001 From: jc <46619361+juancwu@users.noreply.github.com> Date: Tue, 9 Jan 2024 14:34:31 -0500 Subject: [PATCH] update git checkout functions for mac --- zsh/.zshrc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/zsh/.zshrc b/zsh/.zshrc index 9b37732..242a246 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -83,7 +83,7 @@ fcd() { # clone repository # setopt EXTENDED_GLOB -gc() { +cl() { local url=$1 local ghq_dir="$HOME/ghq" @@ -120,6 +120,29 @@ git-prune() { git branch -vv | grep '\[origin/.*: gone\]' | awk '{print $1}' | xargs git branch -d } +# fuzzy find branches and switch to selected branch +gc() { + local selected_branch=$(git branch | fzf | sed 's/^[ \*]*//') + + if [ -n "$selected_branch" ]; then + git checkout "$selected_branch" + else + echo "No branch selected" + fi +} + +# fuzzy find remote branches and switch to selected branch +gcr() { + git fetch + local selected_branch=$(git branch -r | fzf | sed -E 's/^([ \*]*origin\/[\ *]*)*//') + + if [ -n "$selected_branch" ]; then + git checkout "$selected_branch" + else + echo "No branch selected" + fi +} + # Load colors if possible autoload -U colors && colors