Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zhihuitang
Last active April 20, 2020 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhihuitang/917d9739febbaec87c01aa45e80106dc to your computer and use it in GitHub Desktop.
Save zhihuitang/917d9739febbaec87c01aa45e80106dc to your computer and use it in GitHub Desktop.
# Git Fuzzy Checkout
#
# Add the following script to your ~/.gitconfig by run:
# git config --global alias.fuzzy '!f() { git branch -a | grep -m1 -e ${1}.*${2} | sed "s/remotes\/origin\///" | xargs git checkout; }; f'
#
# alias of .gitconfig looks:
[alias]
# fuzzy checkout branch, e.g: git fc feature 739, will checkout branch feature/PGIA-739-deploy-maximum
fc = "!f() { git branch -a | grep -m1 -e ${1}.*${2} | sed \"s/remotes\\/origin\\///\" | xargs git checkout; }; f"
# or
# fc = "!f() { git branch -a | grep -m1 -e ${1}.*${2} | sed 's/remotes\\/origin\\///' | xargs git checkout; }; f"
#
# README
#
# If you want to checkout branch feature/PGIA-739-deploy-maximum
# you can run
# git fc feature 739
# or
# git fc 739
# git fc will find and checkout the first match branch
#
#
# others useful alias
# Squash the last N commits to 1 commit
squash = "!f(){ git reset --soft HEAD~${1} && git commit --edit -m\"$(git log --format=%B --reverse HEAD..HEAD@{1})\"; };f"
last = log -1 HEAD
ls = "!f() { git log --graph --date=relative --pretty=tformat:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%an %ad)%Creset'; };f"
# Find the branch
fb = "!f() { git branch -a | grep ${1} --color=auto ;}; f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment