Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@phrohdoh
Created August 24, 2018 21:57
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 phrohdoh/1e92661bd141d50aa0db12d940a3a683 to your computer and use it in GitHub Desktop.
Save phrohdoh/1e92661bd141d50aa0db12d940a3a683 to your computer and use it in GitHub Desktop.
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