Configure your environment
| Time to read: |
|---|
| 15 minutes |
Configure Git
Handling configuration
How to check global configuration?
git config --list --globalHow to define a global configuration?
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.:
git config --get-regexp "^alias\."Or a more advanced way, with an ordered tabular output:
git config --get-regexp "^alias\." |\
sed -E "s/^alias\.([^ ]+) (.*)$/\1◊\2/" |\
column -c 2 -t -s "◊" |\
sortThis version produce a more readable output as the one bellow:
cb checkout -b
co checkout
fpush push --force-with-lease
l0 log --oneline --decorate=noNote
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.:
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:
git config --global alias.l0 "log --oneline --clear-decorations -20"Which you can simply use with:
git l0You can also produce more complex aliases using shell commands:
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:
git config --global alias.conf '!git config --global --list | sort'My favorites aliases
Quick setup
Quickly define some useful aliases:
# 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 worktreeChecking configuration
Print all your global configuration:
git showconfList all your aliases:
git alias# 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 configto dump all aliases;sedto add a◊separator between alias name and value;columnto display as tabular output;sortto change as ordered by name.
Daily workflow
Compact status:
git st## HEAD (no branch)
?? .idea/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
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:
# …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:
git fpushChecking logs
Show last history log:
git lastcommit b9a34a8072165115d23f11fdfc4becb497f3f359 (HEAD, dev_featA, dev_experiment)
Author: Sylvain Gamel <code@sylvaingamel.fr>
Date: Sun Oct 26 22:40:36 2025 +0100
implement sizeShow history as compact display without decoration (tags and branch names):
git l0 -3b9a34a8 implement size
2369cf1 add test for queue size
b9bf6d1 add test for dequeue on empty queueShow history in compact display with tags and branch names:
git l1b9a34a8 (HEAD, dev_featA, dev_experiment) implement size
2369cf1 (tag: stable) add test for queue size
b9bf6d1 add test for dequeue on empty queueUsing worktrees
List all worktrees in current repository:
git wtl/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:
git wta -b ${NEW_BRANCH} ../${FOLDER_REL_PATH}git wta -b dev_experiment ../rebase-int_exp_wtPreparing worktree (new branch 'dev_experiment')
HEAD is now at b9a34a8 implement sizeRemoving a working tree:
git wtr ../${FOLDER_REL_PATH}git wtr ../rebase-int_A_wtA short way to use worktree Git command to call other sub-commands:
git wtConfigure your IDE
VSCode
More information…
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…
Learn more about GitLens…
Gitlens
JetBrain's IntelliJ
More information…
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.