Skip to content

Instantly share code, notes, and snippets.

@YossiCohen
Created August 12, 2019 10:25
Show Gist options
  • Save YossiCohen/69676e653681fcad9de821a140d2c871 to your computer and use it in GitHub Desktop.
Save YossiCohen/69676e653681fcad9de821a140d2c871 to your computer and use it in GitHub Desktop.
Smart git checkout command - lists branches with filter and allows selection of desired branch
#!/bin/bash
# Usage: gitCheckoutFilter.sh [filter]
# will list all branches with the relevant filter (grep) and allow branch selection
# i.e.
# ~/gitCheckoutFilter.sh yo
# 1) yossi_main
# 2) yossi_panel_redesign
##? 1
# Switched to branch 'yossi_main'
branches=`git branch | grep -i $1`
branches=${branches//\*/}
select branch in $branches;
do
git checkout $branch
exit
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment