Created
December 22, 2021 09:50
-
-
Save mjovanc/ff74b069eaf22e5dcdba244af6c176e5 to your computer and use it in GitHub Desktop.
Simple Git commands aliases for .bashrc
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
# ------------------------------ | |
# Git command aliases/functions | |
# ------------------------------ | |
alias gs='git status' | |
alias gsw='git switch -' | |
alias gfa='git fetch --all' | |
alias gp='git pull' | |
alias gsu='git submodule update' | |
alias ga='git add .' | |
alias grc='git rev-list --count origin/master..HEAD' | |
alias gdt='git diff-tree --name-only -r' | |
alias gpu='git push' | |
alias gpuu='git push --set-upstream origin HEAD' | |
alias gpwl='git push --force-with-lease' | |
alias grom='git rebase origin/master' | |
alias gsl='git stash list' | |
function gl { if [ "$1" = "-a" ] ; then git logg ; elif [ -n "$1" ] ; then git logg -$1 ; else git logg -10 ; fi ; } | |
function gc { git commit -m"$1" ; } | |
function gnb { if [ -n "$1" ] ; then git checkout -b $1 ; else echo "Branch name needed." ; fi ; } | |
function gsp { if [ "$1" ] ; then git stash push -m"$1" ; else echo "Please add a stash message." ; fi ; } | |
function gsq { | |
cnr=$(grc) | |
if (( $cnr > 1 )) ; then | |
git rebase -i HEAD~$cnr | |
else | |
echo "Can not squash less than 2 commits." | |
fi | |
} | |
function gsi { | |
sr=$(git stash list) | |
if [ -n "$sr" ] ; then | |
#sn=$(git rev-list --walk-reflogs --count refs/stash) | |
git stash list | |
echo "Enter index to pop: " | |
read indx | |
if [[ "$indx" =~ ^[0-9]+$ ]] ; then git stash pop --index $indx ; fi | |
fi | |
} | |
function gpm { | |
cnr=$(grc) | |
if (( $cnr > 1 )) ; then | |
echo "Squash the branch before push to master." | |
else | |
if [ "$1" = "-f" ] ; then | |
git push --force-with-lease origin HEAD:master | |
elif [ -z "$1" ] ; then | |
git push --force-with-lease origin HEAD:master | |
else | |
echo "Unrecognized argument - use -f for forced push or leave args list empty" | |
fi | |
fi | |
} | |
alias gg='$(if [ -z $(git rev-parse --show-superproject-working-tree) ]; then git rev-parse --show-toplevel ; else git rev-parse --show-superproject-working-tree ; fi)/gradlew -p $(if [ -z $(git rev-parse --show-superproject-working-tree) ]; then git rev-parse --show-toplevel ; else git rev-parse --show-superproject-working-tree ; fi)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment