Last active
February 6, 2024 05:42
-
-
Save finesse-fingers/ca65c77245d8ceb6653309de70a43459 to your computer and use it in GitHub Desktop.
Git related zsh aliases
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
switch_back_to_branch() { | |
# get the current branch name | |
current_branch=$(git rev-parse --abbrev-ref HEAD) | |
# pull target branch | |
git fetch origin $1:$1 | |
# switch to target branch | |
git checkout $1 | |
# if -d is passed as second argument, delete the current branch | |
if [ "$2" = "-d" ]; then | |
# delete old branch and suppress error if branch is not merged | |
git branch -d $current_branch 2>/dev/null | |
fi | |
# fetch all branches and prune | |
git fetch --all --prune | |
} | |
alias sb='switch_back_to_branch' | |
alias nb='git checkout -b $1' | |
alias status='git status' | |
alias gs='status' | |
alias commit='git commit --all --message $1' | |
alias gc='commit' | |
alias amend='git commit --amend --no-edit --all' | |
alias ga='amend' | |
alias rebase='git pull origin $1 --rebase' | |
alias gr='rebase' | |
# push set to upstream branch | |
push_to_remote_or_normal() { | |
# if upstream branch is not set, set it | |
if [ -z "$(git rev-parse --abbrev-ref @{upstream} 2> /dev/null)" ]; then | |
git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD) | |
else | |
git push | |
fi | |
} | |
alias push='push_to_remote_or_normal' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment