bim

git shortcuts

#!/bin/bash
# Useful git shortcuts and functions for .bashrc or .zshrc

# Quick commit with message
gc() {
    git add -A && git commit -m "$*"
}

# Push current branch
gp() {
    git push origin "$(git branch --show-current)"
}

# Interactive rebase last N commits
gri() {
    git rebase -i HEAD~"${1:-5}"
}

# Show git log as graph
gl() {
    git log --oneline --graph --decorate -n "${1:-20}"
}

# Checkout branch with fuzzy search (requires fzf)
gco() {
    local branch
    branch=$(git branch --all | fzf --height 40% | sed 's/remotes\/origin\///' | xargs)
    git checkout "$branch"
}

# Delete merged branches
gclean() {
    git branch --merged | grep -v '\*\|main\|master' | xargs -n 1 git branch -d
}

# Amend last commit without editing message
gamend() {
    git add -A && git commit --amend --no-edit
}

# Stash with message
gss() {
    git stash push -m "$*"
}