Skip to content

Instantly share code, notes, and snippets.

@hiveer
Last active May 15, 2018 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiveer/bdd8b42969ca128525ea0b2cdbfeef12 to your computer and use it in GitHub Desktop.
Save hiveer/bdd8b42969ca128525ea0b2cdbfeef12 to your computer and use it in GitHub Desktop.
Easy way to find out your recent branch and checkout to them
Add below code to the file `~/.bashrc`
# this will file recent 10 branches
alias recent_branches="git for-each-ref --sort='-authordate:iso8601' --format='%(refname:short)' --count 10 refs/heads"
function recent() {
read -a arr <<< $(recent_branches)
for ((i = 0; i < ${#arr[@]}; ++i)); do
position=$(($i))
echo "$position ${arr[$i]}"
done
}
# checkout to branch with index num
function gckp() {
arr=($(recent_branches))
git checkout ${arr[$@]}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment