Git is a wide spread version control system.

Before talking about those aliases and parameters I have set in my user configuration I’d like to spend some words on how this works.

Git’s configuration comes in three levels: system, user (aka global) and repository. The first one affects the whole system (every user and every local repository), the second regards every repository owned by a particular user while the third affects only a specified repository.

I will be editing my user configuration. You can either edit directly the related file (~/.gitconfig) or use Git’s built in command line conf-editor. Since the former method is discouraged I will illustrate the latter. Its syntax for the global context is as follows:

$ git --global <section.parameter_name> <value>

So let’s have some fun!

Autocorrect commands

Yup, Git can correct your typos. Just specify how may tenths of a second it has to wait for you to check that the command that’s about to run is correct:

$ git config --global help.autocorrect 10

screenshot-from-2017-02-28-16-40-18

Default editor

In love with a text editor? Good news you can change Git’s default for editing commit messages.

$ git config --global core.editor nano

Aliases

When you alias a command, it means that you can type an alternative word of your choice instead of the whole (maybe long and complex) command. For instance, “git config alias.ci commit” will let you type “git ci” instead of “git commit“. Now some more:

  • C-h-e-c-k-o-u-t: 90% of the times I get this spelled wrong.
    $ git config --global alias.co checkout
  • Git branch: just a shorthand.
    $ git config --global alias.br branch
  • Who likes typing the same parameter 100 times a day.
    $ git config --global alias.cm "commit -m"
  • Easy to get tired of typing this one.
    $ git config --global alias.s status
  • And my favorite (draws a nice and clean log with branches and tags):
    $ git config --global alias.tree "log --all --decorate --oneline --graph"

    Git log

  • For short-memory folks like me (prints the last commit):
    $ git config --global alias.last "log -1 HEAD"
  • Unstage a file in a quick way.
    $ git config --global alias.unstage "reset HEAD --"

That’s all, share and comment yours!


Source: Git Essentials book (Ferdinando Santacroce)

Advertisements