Git Checkout Using Partial Branch Name Matching

2020-07-13 16:07 (4 years ago) ytyng

How about this? zsh bash

CO() {
if [ ! "$1" ] ; then
echo 'usage: CO branch-name'
git branch
return
fi
branchname=$(git branch --format="%(refname:short)" | grep $1)
if [ ! "$branchname" ]; then
echo "branch name not found. $1"
echo "branch names:"
git brahcn
return
fi
git checkout $branchname
}
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.

Archive

2025
2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011