Skip to content

Instantly share code, notes, and snippets.

@james-pre
Last active March 28, 2025 07:09
Show Gist options
  • Save james-pre/4b66beda27ec3dc117e685360a5eeade to your computer and use it in GitHub Desktop.
Save james-pre/4b66beda27ec3dc117e685360a5eeade to your computer and use it in GitHub Desktop.
Useful `git` aliases
#!/bin/bash
# Adds some useful git aliases
echo "Adding aliases"
# Lists changes (i.e. commit messages)
# "- " prefixed before each line after any whitespace for easily making a markdown list
# You can optionally provide from and to tags.
# `git ls-changes` will list changes from the last tag to HEAD
# `git ls-changes tag_a` will list changes from tag_a to HEAD
# `git ls-changes tag_a tag_b` will list changes from tag_a to tag_b
git config --global alias.ls-changes '!f() { from=${1:-$(git describe --tags --abbrev=0)}; to=${2:-HEAD}; git log --format=%B "$from".."$to" | grep -v -e "^$" | sed "s/^\(\s*\)/\1- /"; }; f'
# Shortcut for `git ls-changes`
git config --global alias.ls 'ls-changes'
# Allows you to easily bump an NPM release, push it to remote, and get a list of the changes for that release
git config --global alias.npm-version '!f() { git ls && npm version "$1" && git push && git push --tags; }; f'
# Easily revert the last release when you mess up. The last commit should be the one that changed the release.
git config --global alias.revert-version '!f() { git push origin ":v$1" && git reset --hard HEAD~1 && git tag --delete "v$1" && git push --force; }; f'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment