Skip to content

Instantly share code, notes, and snippets.

@bbody
Last active July 6, 2023 07:45
Show Gist options
  • Save bbody/047dcd6155cd5467a7e3f0f3449a8249 to your computer and use it in GitHub Desktop.
Save bbody/047dcd6155cd5467a7e3f0f3449a8249 to your computer and use it in GitHub Desktop.
A few Git shortcuts I use
[alias]
# Lists local branches ordered by last commit date, showing the latest branches at the bottom
brrr = for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
# Amends staged items to current commit
extend = commit --no-edit --amend
# Shorthand for checkout
co = checkout
# Shorthand for checkout trunk, it will determine the main branch e.g. master or main, and check it out
cot = !git co `git cwt`
# Checks out a new branch, expects a name to follow
cob = checkout -b
# Shorthand for branch
br = branch
# Shorthand for commit
c = commit
# Shorthand for commit with message
cm = commit -m
# Shorthand for commit all with message
cam = commit -am
# Shorthand for status
st = status
# Returns the current upstream branch name
cwub = rev-parse --abbrev-ref HEAD
# Returns the current branch name
cwb = !git cwub | sed 's@^origin/@@'
# Returns the current main branch name at origin
cwut = !git rev-parse --abbrev-ref `git symbolic-ref refs/remotes/origin/HEAD`
# Returns the current origin branch name
cwt = !git cwut | sed 's@^origin/@@'
# Merges main branch
mt = !git merge `git cwt`
# Checks out the main branch
cot = !git checkout `git cwt`
# Resets hard to current upstream branch
resetty = !git reset --hard `git cwub`
# Shorthand for fetch
f = fetch
# Fuzzy checkout
fc = "!f() { git branch -a | grep -m1 -e ${1}.*${2} | sed \"s/remotes\\/origin\\///\" | xargs git checkout; }; f"
@bbody
Copy link
Author

bbody commented Jul 4, 2023

The above commands will need to go into your ~/.gitconfig file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment