Skip to content

Configure your environment

Time to read:
15 minutes

Configure Git

Handling configuration

How to check global configuration?

bash
git config --list --global

How to define a global configuration?

bash
git config --global {CONFIG_KEY} {CONFIG_VALUE}

Where:

  • {CONFIG_KEY} is one of the available configurations, as defined in the Git reference.
  • {CONFIG_VALUE} is the value for the configuration key.

Git Editor

You can check how to link an editor with Git in the introduction section.

Define aliases

Git can support custom command aliases. Those are independent of your own shell aliases and are very specific to Git.

Why?

Why would you use Git aliases instead of shell ones?

Because Git configuration is not depending on your specific current shell. So it's easier to use them, even when you switch between two different shells, like zsh and nushell.

Check aliases

Aliases are simply configuration.

So when you need to dispay all aliases you can just display all those keys.

I can be done in a basic way by filtering only the configuration keys starting with alias.:

bash
git config --get-regexp "^alias\."

Or a more advanced way, with an ordered tabular output:

bash
git config --get-regexp "^alias\." |\
  sed -E "s/^alias\.([^ ]+) (.*)$/\1◊\2/" |\
  column -c 2 -t -s "◊" |\
  sort

This version produce a more readable output as the one bellow:

console
cb        checkout -b
co        checkout
fpush     push --force-with-lease
l0        log --oneline --decorate=no

Note

I use the character to separate alias name and value. This avoid conflicts with other shell specific separator like |. But you will see that when an alias is defined for this command it won't be properly displayed.

That's a small limitation from column command.

Create a new alias

To create a new alias you create a new global configuration key starting with alias.:

bash
git config --global alias.{NAME} "{CLI_COMMAND}"

Where:

  • {NAME} will be the name of the alias command.
  • {CLI_COMMAND} is the value of the git command

For example here how you can define a simple l0 command to print last 20 commits in compact form:

bash
git config --global alias.l0 "log --oneline --clear-decorations -20"

Which you can simply use with:

bash
git l0

You can also produce more complex aliases using shell commands:

bash
git config --global alias.{NAME} "!{SHELL_COMMAND}"

For example, to display ordered list of global configuration, we can define an alias as follow to combine both git and sort commands:

bash
git config --global alias.conf '!git config --global --list | sort'

My favorites aliases

Quick setup

Quickly define some useful aliases:

bash
# Configuration
git config --global alias.showconf "config --global --list"
# ... simple option
git config --global alias.alias "config --get-regexp '^alias\.'"
# ... or more advance sorted tabular output
git config --global alias.alias '!git config --get-regexp "^alias\." | sed -E "s/^alias\.([^ ]+) (.*)$/\1\◊\2/" | column -t -s "◊" | sort'

# Branches
git config --global alias.st "status -sb"
git config --global alias.br "branch --format='%(HEAD) %(color:brightcyan)%(refname:short)%(color:reset) - %(contents:subject) %(color:green)(%(committerdate:relative))%(color:reset) [%(color:yellow)%(authorname)%(color:reset)]' --sort=-committerdate"
git config --global alias.sw switch
git config --global alias.fpush "push --force-with-lease"

# Logs
git config --global alias.last "log -1 HEAD"
git config --global alias.l0 "log --oneline --decorate=no"
git config --global alias.l1 "log --oneline"

# Worktrees
git config --global alias.wtl "worktree list"
git config --global alias.wta "worktree add"
git config --global alias.wtr "worktree remove"
git config --global alias.wt worktree

Checking configuration

Print all your global configuration:

bash
git showconf

List all your aliases:

bash
git alias
bash
# Remove line breaks and trailing `\`to define alias,
# this is only for readability…
git config --global alias.alias '!git config --get-regexp "^alias\."\
| sed -E "s/^alias\.([^ ]+) (.*)$/\1◊\2/"\
| column -t -s "◊"\
| sort'

For this one I repeat again the definition in a more readable format:

  • git config to dump all aliases;
  • sed to add a separator between alias name and value;
  • column to display as tabular output;
  • sort to change as ordered by name.

Daily workflow

Compact status:

bash
git st
console
## HEAD (no branch)
?? .idea/
console
interactive rebase in progress; onto 2369cf1
Last commands done (3 commands done):
   reset onto
   edit b9a34a8 implement size
  (see more in file .git/rebase-merge/done)
Next commands to do (2 remaining commands):
   pick f727659 implement dequeue
   pick d0568eb implement enqueue
  (use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch 'rebase1' on '2369cf1'.
  (use "git commit --amend" to amend the current commit)
  (use "git rebase --continue" once you are satisfied with your changes)

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .idea/

nothing added to commit but untracked files present (use "git add" to track)

Show branches in colored display

bash
git br
* (no branch, rebasing rebase1) - implement size (7 days ago) [Sylvain Gamel]
  dev_experiment - implement size (7 days ago) [Sylvain Gamel]
  dev_featA - implement size (7 days ago) [Sylvain Gamel]
  rebase1 - implement enqueue (7 days ago) [Sylvain Gamel]
  main - fix bug (4 weeks ago) [Sylvain Gamel]

Changing current branch with switch command:

bash
# …to an existing branch
git sw ${BRANCH_NAME}

# …to a new branch
git sw -c ${BRANCH_NAME}

# …to previous branch
git sw -

Push to remote but force in case of amend or other rewritten history:

bash
git fpush

Checking logs

Show last history log:

bash
git last
console
commit b9a34a8072165115d23f11fdfc4becb497f3f359 (HEAD, dev_featA, dev_experiment)
Author: Sylvain Gamel <code@sylvaingamel.fr>
Date:   Sun Oct 26 22:40:36 2025 +0100

    implement size

Show history as compact display without decoration (tags and branch names):

bash
git l0 -3
console
b9a34a8 implement size
2369cf1 add test for queue size
b9bf6d1 add test for dequeue on empty queue

Show history in compact display with tags and branch names:

bash
git l1
console
b9a34a8 (HEAD, dev_featA, dev_experiment) implement size
2369cf1 (tag: stable) add test for queue size
b9bf6d1 add test for dequeue on empty queue

Using worktrees

List all worktrees in current repository:

bash
git wtl
console
/Users/sylvain/dev/lab/git-tutorials/playgrounds/rebase-int_start   b9a34a8 (detached HEAD)
/Users/sylvain/dev/lab/git-tutorials/playgrounds/rebase-int_A_wt    b9a34a8 [dev_featA]
/Users/sylvain/dev/lab/git-tutorials/playgrounds/rebase-int_exp_wt  b9a34a8 [dev_experiment]

Add a new worktrees to current repository:

bash
git wta -b ${NEW_BRANCH} ../${FOLDER_REL_PATH}
bash
git wta -b dev_experiment ../rebase-int_exp_wt
console
Preparing worktree (new branch 'dev_experiment')
HEAD is now at b9a34a8 implement size

Removing a working tree:

bash
git wtr ../${FOLDER_REL_PATH}
bash
git wtr ../rebase-int_A_wt

A short way to use worktree Git command to call other sub-commands:

bash
git wt

Configure your IDE

VSCode

More information…

Visual Studio Code icon

Learn more about VSCode…
Visual Studio Code

VSCode proposes good git support, but some advanced features will either require you to jump to your terminal or install specific extensions.

My personal choice would go to GitLens, that will bring you more advanced features, such as blame annotation right in the editor or interactive rebase. A pro plan exists, but you won't need it.

More information…

Gitlens icon

Learn more about GitLens…
Gitlens

JetBrain's IntelliJ

More information…

IntelliJ IDEA

Learn more about IntelliJ…
IntelliJ IDEA

All JetBrains IDEs that I’ve tried come with excellent support for git cms. You do not need to add an external extension.