Last active
April 5, 2024 02:16
-
-
Save markddavidoff/43cdae787afb90c13e04fb77329c01f8 to your computer and use it in GitHub Desktop.
git shell plugins / functions / aliases
This file contains 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
# warning these are hacky script thrown together with no care or understanding, so NO WARRANTY, USE AT YOUR OWN RISK | |
# you can install the git zsh plugin for more goodies, but these are some customized versions | |
# git zsh plugin: https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/git/git.plugin.zsh | |
# also check out grecent | |
alias fetch='git fetch --all' | |
alias switch='git checkout' | |
alias switchb='gcb' | |
alias pull='ggpull' | |
alias branch='gcb' | |
alias push='ggpush' | |
alias forcepush='ggfl' | |
alias recentbranches="git for-each-ref --sort=-committerdate --count=10 --format='%(refname:short)' refs/heads/" | |
alias switchback='git checkout @{-1}' | |
function switchm() { | |
# switch to master or main | |
mbranch=$((git rev-parse -q --verify master > /dev/null && echo "master") || (git rev-parse -q --verify main> /dev/null && echo "main")) | |
git checkout "$mbranch" | |
} | |
function switchprev() { | |
# switch to previous non-master/main branch | |
i=0 | |
current_branch=$(git rev-parse --abbrev-ref HEAD) | |
while [ true ] | |
do | |
i=$(( $i + 1 )) | |
prev=$(git rev-parse --abbrev-ref @{-$i}) | |
if [[ "$prev" == "master" ]]; then | |
continue | |
fi | |
if [[ "$prev" == "main" ]]; then | |
continue | |
fi | |
if [[ "$prev" == "$current_branch" ]]; then | |
continue | |
fi | |
break | |
done | |
git checkout $prev | |
} | |
function rbm() {( | |
# rebase current branch on most recent master/main branch. | |
# lots of ways to do this, this is a lazy one. | |
set -e | |
curr_branch=$(git rev-parse --abbrev-ref HEAD) | |
git checkout main || git checkout master | |
main_branch=$(git rev-parse --abbrev-ref HEAD) | |
git pull origin $main_branch | |
git checkout $curr_branch | |
git rebase $main_branch | |
)} |
Author
markddavidoff
commented
Apr 5, 2024
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment