Skip to content

Instantly share code, notes, and snippets.

@metaskills
Created October 22, 2012 15:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metaskills/3932004 to your computer and use it in GitHub Desktop.
Save metaskills/3932004 to your computer and use it in GitHub Desktop.
#!/bin/zsh
export GIT_EDITOR="subl -w"
if [[ -x `which git` ]]; then
# Hub
if [[ -x `which hub` ]]; then
# alias git=hub
fi
# Promt Work
function git-branch-name () {
git branch 2> /dev/null | grep "^\*" | sed "s/^\*\ //"
}
function git-dirty () {
git status | grep "nothing to commit (working directory clean)"
echo $?
}
function git-prompt() {
branch=$(git-branch-name)
if [[ x$branch != x ]]; then
if [[ $branch = "(no branch)" ]]
then
dirty_color=$fg[yellow]
echo " %{$dirty_color%}$branch%{$reset_color%}"
else
dirty_color=$fg[green]
if [[ $(git-dirty) = 1 ]] { dirty_color=$fg[red] }
[ x$branch != x ] && echo " %{$dirty_color%}$branch $(git-stash-count)%{$reset_color%}"
fi
fi
}
function git-stash-count() {
branch=$(git-branch-name)
count=$(git stash list | grep "${branch}" | wc -l | awk '{print $1}')
[ $count != 0 ] && echo "($count)"
}
# Other Macros
function grbm () {
local branch=$(git-branch-name)
git checkout master
git pull origin master
git checkout "${branch}"
git rebase master
}
function grbmc () {
local branch=$(git-branch-name)
grbm
git checkout master
git merge "${branch}"
git push origin master
if [[ -f .git/hooks/post-push ]]; then
.git/hooks/post-push
fi
git checkout "${branch}"
}
function grbd () {
local branch=$(git-branch-name)
git checkout develop
git pull origin develop
git checkout "${branch}"
git rebase develop
}
function grbdc () {
branch=$(git-branch-name)
grbd
git checkout develop
git rebase "${branch}"
git push origin develop
if [[ -f .git/hooks/post-push ]]; then
.git/hooks/post-push
fi
git checkout "${branch}"
}
function gtag () {
git tag -a -m "Tagging Version ${1}" $1
git push origin master
git push --tags
}
function gsp () {
git stash pop "stash@{$1}"
}
fi
# Logging
alias gfame='git log | git shortlog -n -s'
alias gfame2="ruby ~/.zshkit/bin/gscore.rb"
alias glog="git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short"
alias glog_ss="git log --shortstat"
alias glog_ns="git log --name-stat"
alias glog_p="git log -p"
alias glog_s="git log --pretty=short"
alias glog_g="git log --graph"
# Rebasing
alias grc='git rebase --continue'
alias grs='git rebase --skip'
alias gra='git rebase --abort'
# Diff
alias gd='git diff'
alias gdw='git diff --word-diff'
alias gde='git diff | subl'
alias gdpe='git diff --no-prefix | subl'
# Unorganized
alias gst='git status -sb'
alias ga='git add -i'
alias gco='git checkout'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gspp='git stash pop'
alias gb='git branch'
alias gba='git branch -a'
alias gcla='git clean -x -d -f'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment