Skip to content

Instantly share code, notes, and snippets.

@mjlescano
Last active November 13, 2019 18:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjlescano/399970b9afde43d10cb6 to your computer and use it in GitHub Desktop.
Save mjlescano/399970b9afde43d10cb6 to your computer and use it in GitHub Desktop.
Git Minimal aliases. e.g "push" to push current branch
alias status="_exec git status"
alias s="git status --short"
alias fetch="_exec git fetch"
alias stash="_exec git stash"
alias commit="_exec git commit"
alias checkout="_exec git checkout"
alias add="_exec git add"
alias diff="_exec git diff"
alias co="checkout"
alias dif="diff"
alias pul="pull"
_exec() {
echo "$(tput setaf 6)> $@$(tput sgr0)"
eval $@
}
get_git_branch_string() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
pull() {
_exec git pull $(git remote show) $(get_git_branch_string) $@
}
push() {
_exec git push $(git remote show) $(get_git_branch_string) $@
}
reset() {
_exec git reset $(git remote show)/$(get_git_branch_string) --hard $@
}
compare() {
# First param, optional, the branch wich compare the current branch
if [ -z "$1" ]; then
local with="master"
else
local with="$1"
fi
# Second param, optional, the branch to compare, defaults to current
if [ -z "$2" ]; then
local branch=$(get_git_branch_string)
else
local branch="$2"
fi
local repo=$(expr "$(git config --get remote.origin.url)" : '.*:\(.*\)\.git')
_exec open "https://github.com/$repo/compare/$with...$branch"
}
cod() {
# First param, optional, the branch wich compare the current branch
if [ -z "$1" ]; then
local base="master"
else
local base="$1"
fi
local branch=$(get_git_branch_string)
_exec git fetch
echo ''
_exec git branch -f "$base" $(git remote show)/"$base"
echo ''
_exec git checkout "$base"
echo ''
_exec git branch -D "$branch"
echo ''
_exec git fetch --prune
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment