Aliases

We can create personal Git commands using aliases. First, let's take a look at how to format the output. For this, suppose you don't like the output of neither the git log command, nor the output of git log --oneline. We can create a personalized output like this:

git log --pretty=format:'%Cgreen%an%Creset committed %Cgreen%h%Creset on %Cgreen%cd%Creset'

Here %an stands for author name, %h stands for short hash, and %cd stands for commit date. %C is for setting and resetting the color. You can check the complete list of possible placeholders and styles here .

Aliases 1
Aliases 2

Of course typing all of this every time we want to use the command is very time consuming. But in Git we can set up aliases for any command we want (even the built in ones). First we need to define a new property in the alias section of the Git configuration. So we run:

git config --global alias.lg "log --pretty=format:'%Cgreen%an%Creset committed %Cgreen%h%Creset on %Cgreen%cd%Creset'"

Here lg will be the name of our custom command, and in between quotes we type our command. We can see (and edit) our command in VS Code.

Aliases 3

Now we can define an alias for un-staging files.

git config --global alias.unstage 'restore --staged .'

With it we can restore all the files in the staging area with one simple command.

git unstage
Aliases 4