Please have fun with git aliases | Toucan Toco

Categories :

Table of Contents

git is a really powerful SCM but not always fun. Let’s change that!

As many tech companies, we use git to manage our codebase. In this blog post, I will show you the main aliases we use on a daily basis at Toucan Toco. I will not dig into how to manage and write your own complex git aliases as there are already a lot of nice articles about it (I really recommand the Atlassian blog post One weird trick for powerful Git aliases to know more about it). Let’s just say for now that if you want to use one of the aliases below, just add it to your ~/.gitconfig in [alias] section.

So let’s talk about the Toucan Toco git aliases! Some of them are really useful and some of them are… just “For the LULZ”.

SpongeBob loves git

The usual aliases:

st = status
ci = commit
plog = log --pretty=tformat:'%h\t%cr\t%cn\t\t%s'
plogcolor = log --pretty=tformat:'%C(bold blue)%h%Creset\t%Cblue%cr%Creset\t%cn\t\t%Cgreen%s%Creset'

Nothing to explain here, there are shotrcut for usual commands.

Reset funny aliases

# Undo the last commit
# "Oops I did it again" - Britney Spears
oops = reset --soft HEAD^

# Hard clean your current branch
# "Time to clean up." - Nikita
nikita = reset --hard

# Clean all untracked files
# "It's my best friend. Always happy. No questions." - Leon The Professionnal
leon = clean -f

Blame funny aliases

# Replace blame by congrat
# "Why always me" - Mario Balotelli
congrat = blame

We never understood why blame is blame… At Toucan Toco, we are kind and loving people so we decided to congratulate instead of blaming :) (plus sometimes, you just want to know who wrote these brillant snippets of code!)

Push funny aliases

# Force push
# "The shortest distance between two points is whatever route Chuck takes." - Chuck Norris Facts
norris = push --force

# Dedicated to all the lovers of the french democracy
quarante-neuf-trois = !git norris
consensual = !git norris

Little tech part: it’s not possible to create git aliases from others. Here you want to use the same alias without redefining it. So the workaround here, is to configure quarante-neuf-trois as a bash command which actually runs git norris. Thus you are able to create alias from alias :)

Archive alias

# Create an archive of the project's current state
tar = "!_() { \
                        git archive --format=tar -o ${1:-./project.tar} HEAD; \
                }; _"

This alias is pretty interesting because it creates a tar archive of the project’s current state. You can specify the path of the archive you want to create, otherwise a project.tar file will be created right where you are.

#e.g.:
git tar /tmp/myproject-`date +%Y%m%d`.tar

Top Committers

# List the top N committers
topcommitters = "!_() { \
			git shortlog -sn --no-merges | head -n${1:-10}; \
		}; _"

# List the top 10 committers
top10 = !git topcommitters

Once again you can use the workaround to create the alias top10 from another alias. You can specify how many committers you want to see with topcommitters as follows:

#e.g. to list the top 20:
git topcommitters 20

Misc aliases

# List changes from last pull
# "Do you remember?" - Earth Wind and Fire
remember = !git plogcolor ORIG_HEAD.. --no-merges

# Display only your own commits
# "It's all about me" - Kim Kardashian
kardashian = "!_() { \
			git plogcolor --author=\"`git config user.name`\"; \
		}; _"

# When you have no idea for a commit message
random = "!_() { \
		git commit -m \"`curl -s http://whatthecommit.com/index.txt`\" \
	}; _"

# Display logs as a funky tree :)
# "Last Christmas, I gave you my heart" - George Michael
# inspired by
#       https//hackernoon.com/lesser-known-git-commands-151a1918a60#.9qtmgtbcs
treesmas = log --graph --abbrev-commit --decorate --all --format=format:'%C(bold blue)%h%C(reset) - %C(cyan)%aD%C(reset) - %an %C(blue)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n %C(green)%s%C(reset)'

# Set tracking information for the current branch
# "Swims upstream because downstream is too mainstream"
# 	cf http://cdn.quotationof.com/images/upstream-quotes-5.webp
# inspired by
#	https://aaronbonner.io/post/80766268890/git-alias-to-simplify-setting-upstream-branch
mainstream = !git branch --set-upstream-to=origin/`git symbolic-ref --short HEAD`

All the aliases

Finally a typical Toucan Toco’s git alias section could be like above:

[alias]

        #######################################################################
        # Usual aliases
        #######################################################################
        st = status
        ci = commit
        plog = log --pretty=tformat:'%h\t%cr\t%cn\t\t%s'
        plogcolor = log --pretty=tformat:'%C(bold blue)%h%Creset\t%Cblue%cr%Creset\t%cn\t\t%Cgreen%s%Creset'

        #######################################################################
        # Fun aliases from Toucan Toco
        #######################################################################

        # Undo the last commit
        # "Oops I did it again" - Britney Spears
        oops = reset --soft HEAD^


        # List changes from last pull
        # "Do you remember?" - Earth Wind and Fire
        remember = !git plogcolor ORIG_HEAD.. --no-merges


        # Hard clean your current branch
        # "Time to clean up." - Nikita
        nikita = reset --hard


        # Clean all untracked files
        # "It's my best friend. Always happy. No questions." - Leon The Professionnal
        leon = clean -f


        # Replace blame by congrat
        # "Why always me" - Mario Balotelli
        congrat = blame


        # Display only your own commits
        # "It's all about me" - Kim Kardashian
        kardashian = "!_() { \
                                git plogcolor --author=\"`git config user.name`\"; \
                        }; _"


        # Force push
        # "The shortest distance between two points is whatever route Chuck takes." - Chuck Norris Facts
        norris = push --force
        # Dedicated to all the lovers of the french democracy
        quarante-neuf-trois = !git norris


        # Top Commiters
        topcommiters = "!_() { \
                                git shortlog -sn --no-merges | head -n${1:-10}; \
                        }; _"
        top10 = !git topcommiters


        # Create an archive of the project's current state
        tar = "!_() { \
                        git archive --format=tar -o ${1:-./project.tar} HEAD; \
                }; _"


        # When you have no idea for a commit message
        random = "!_() { \
                        git commit -m \"`curl -s http://whatthecommit.com/index.txt`\" \
                }; _"


        #######################################################################
        # Fun aliases inspired by others
        #######################################################################

        # Display logs as a funky tree :)
        # "Last Christmas, I gave you my heart" - George Michael
        # inspired by
        #       https//hackernoon.com/lesser-known-git-commands-151a1918a60#.9qtmgtbcs
        treesmas = log --graph --abbrev-commit --decorate --all --format=format:'%C(bold blue)%h%C(reset) - %C(cyan)%aD%C(reset) - %an %C(blue)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n %C(green)%s%C(reset)'

        # Set tracking information for the current branch
        # "Swims upstream because downstream is too mainstream"
        #       cf http://cdn.quotationof.com/images/upstream-quotes-5.webp
        # inspired by
        #       https://aaronbonner.io/post/80766268890/git-alias-to-simplify-setting-upstream-branch
        mainstream = !git branch --set-upstream-to=origin/`git symbolic-ref --short HEAD`

Now it’s your time to play with git aliases and don’t hesitate to share yours with us :)

This is a heading 2

This is a paragraph

This is a heading 2

This is a paragraph

Table of Contents