Last active
May 15, 2018 09:27
-
-
Save hiveer/bdd8b42969ca128525ea0b2cdbfeef12 to your computer and use it in GitHub Desktop.
Easy way to find out your recent branch and checkout to them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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