Skip to content

Instantly share code, notes, and snippets.

@phrohdoh
Created Aug 24, 2018
Embed
What would you like to do?
git aliases

Add aliases by running each of the following commands once:

$ git config --global alias.rel "rev-parse --show-prefix"
$ git config --global alias.root "rev-parse --show-toplevel"

Example usage:

$ pwd
/Users/phrohdoh/src/dotnet-core-oauth2-server/cauth-mvc/Models/External/Slack

$ git root
/Users/phrohdoh/src/dotnet-core-oauth2-server/cauth-mvc

$ git rel
Models/External/Slack/

Bonus alias aliases!

$ git config --global alias.aliases "! git config --get-regexp ^alias\. | sed -e s/^alias\.// -e s/\ /\ =\ /"

Run it to see something similar to the following:

$ git aliases

root = rev-parse --show-toplevel
rel = rev-parse --show-prefix
aliases = ! git config --get-regexp ^alias\. | sed -e s/^alias\.// -e s/\ /\ =\ /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment