Skip to content

Instantly share code, notes, and snippets.

@nuffin
Last active December 18, 2024 04:34
Show Gist options
  • Save nuffin/0ec698e8f8fbc3a6ed4e727fcc8d9bed to your computer and use it in GitHub Desktop.
Save nuffin/0ec698e8f8fbc3a6ed4e727fcc8d9bed to your computer and use it in GitHub Desktop.
git alias
[alias]
adog = log --all --decorate --oneline --graph
adogf = log --all --decorate --oneline --graph --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'
## fetch origin main and merge into local main
fmain = "!f() { git fetch --all --prune && git fetch . origin/main:main; }; f"
ff = "!f() { branch=${1:-main}; git fetch --all --prune && git fetch . origin/$branch:$branch; }; f"
## rebase main with stash
rbmain = "!f() { git stash && git rebase main && git stash pop; }; f"
rb = "!f() { branch=${1:-main}; git stash && git rebase $branch && git stash pop; }; f"
## pull with stash
spsp = "!f() { git stash && git pull && git stash pop; }; f"
## use fzf to choose commits
fzf = "!f() { git log --oneline --pretty=format:\"%h %cd %s\" --date=iso | fzf --multi --preview 'git show {+1}' | awk '{print $1}'; }; f"
## output latest N commits hash
latest = "!f() { branch=${1}; n=${2:-1}; git log ${branch} -n ${n} --pretty=format:\"%h\" --reverse; }; f"
cp = "!f() { branch=${1}; n=${2:-1}; git cherry-pick $(git latest ${branch} ${n}); }; f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment