Last active
November 13, 2019 18:59
-
-
Save mjlescano/399970b9afde43d10cb6 to your computer and use it in GitHub Desktop.
Git Minimal aliases. e.g "push" to push current branch
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
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