Git Configuration and Aliases
One of the first things I do when setting up a new development environment is to configure Git. These commands improve the Git command line experience for me and help when working with branches and forked remotes.
Git Configuration
For any of these options, --global
will impact all repos for the currently logged-in user. Remove it to only impact the current local repository.
User Name
git config --global user.name "Erik Schumacher"
User Email
git config --global user.email "my@email.com"
Default Editor
git config --global core.editor "vim"
Personally, I prefer vim or neovim, but you can replace “vim” with whatever editor you like to work with. If necessary, you can provide a path to the editor executable (ex on windows: "C:\Path\to\editor.exe"
). If your editor comes up with an empty document or is having issues, try adding --wait
(ex: git config --global core.editor "'C:\Path\to\editor.exe' --wait"
).
Git Aliases
git lola
git config --global alias.lola "log --graph --decorate --pretty=oneline --abbrev-commit --all"
Here is an example output of git lola
:
Here is a breakdown of the options passed to log by this alias:
- log
- Show commit log
- graph
- Draw a text-based graphical representation on the left (see the red lines in the above example).
- decorate
- Include ref names of shown commits (i.e. branch names, tags, etc)
- pretty=oneline
- For each commit, show a single line containing <hash> <title line>.
- abbrev-commit
- Reduce the 40-byte commit hash to 7 bytes.
- all
- Include all commits in the log output.
git lol
git config --global alias.lol "log --graph --decorate --pretty=oneline --abbrev-commit"
This is almost identical to lola alias above, except we omit --all
.
If using the same repo and checked out commit in the git lola example above, the output of git lol
is:
Since git lol
does not specify --all
, only the current commit’s history is shown. Branch ft-p-versus-np
is not an ancestor of HEAD
, thus it is not included in the output.
git lol
is especially useful for repositories with many branches or contributors.
git st
git config --global alias.st "status"
I execute this command at a high frequency – and being a certain level of lazy, shortening git status
to git st
is a must for me.
Summary
Those are the basics that I can’t live without when setting up a new development environment. There are many more situational but useful options. Use git <command> --help
or consult Git’s documentation to learn more and experiment!