Skip to content

Instantly share code, notes, and snippets.

@shmup
Created January 5, 2026 18:19
Show Gist options
  • Select an option

  • Save shmup/9752759a1b6ccbb19c545d32a96830c7 to your computer and use it in GitHub Desktop.

Select an option

Save shmup/9752759a1b6ccbb19c545d32a96830c7 to your computer and use it in GitHub Desktop.
git shit for bashrc
# ~/.gitrc: git-related aliases and functions
# config (dotfiles bare repo)
alias config="g --git-dir=$SRC/home-bare/ --work-tree=$HOME"
alias cs='config status'
alias cap='config add -p'
# gitsimp
alias g='git'
alias gap='g add -p'
alias gc='g checkout'
alias gca='g commit --amend -v'
alias gco='git checkout $(git branches | sort -r | fzy -l 50 | cut -d " " -f 2)'
alias gcot='git checkout $(git tag -l -n1 | fzy -l 50 | cut -d " " -f 1)'
alias gcp='g cherry-pick'
alias gcv='g commit -v'
alias gd='g diff'
alias gdc='gd --cached'
alias gra='g rebase --abort'
alias grc='g rebase --continue'
alias gs='g status'
alias gsk='g stash -k'
alias gcd1='g clone --depth 1'
grim() {
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" == "main" ]; then
commit_count=$(git rev-list --count HEAD)
if [ "$commit_count" -le 50 ]; then
g rebase -i --root
else
g rebase -i HEAD~50
fi
else
g rebase -i main
fi
}
# prevent checkout -b, use switch -c
git() {
if [[ "$1" == "checkout" && "$2" == "-b" ]]; then
echo "NO: Use git switch -c instead!"
return 1
else
command git "$@"
fi
}
# functions
gclonecd() {
git clone "$1" && cd "$(basename "$1" .git)"
}
gsr() {
git submodule deinit -f $1
git rm -f $1
}
csr() {
config submodule deinit -f $1
config rm -f $1
}
# git prompt
if ! type __git_ps1 &>/dev/null && [ -e /usr/share/git-core/contrib/completion/git-prompt.sh ]; then
. /usr/share/git-core/contrib/completion/git-prompt.sh
fi
if type __git_ps1 &>/dev/null; then
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWCOLORHINTS=1
export PROMPT_DIRTRIM=2
# disable git prompt for slow repos (> 100MB .git directory)
__prompt_command() {
local git_dir_size
if [ -d .git ]; then
git_dir_size=$(du -s .git 2>/dev/null | cut -f1)
if [ "$git_dir_size" -gt 100000 ]; then
PS1="\u@\h:\w\$ "
return
fi
fi
__git_ps1 "\u@\h:\w" "\\$ "
}
export PROMPT_COMMAND='__prompt_command'
fi
# fzf-git integration
[[ -f $SRC/fzf-git.sh/fzf-git.sh ]] && source $SRC/fzf-git.sh/fzf-git.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment