Last active
July 6, 2023 07:45
-
-
Save bbody/047dcd6155cd5467a7e3f0f3449a8249 to your computer and use it in GitHub Desktop.
A few Git shortcuts I use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above commands will need to go into your
~/.gitconfig
file