GIT - 4.10 History and creation of new orders with alias
In this lesson we go a little further with the git log command and then define a permanent Git alias to shorten it. The starting point is a clean test repository on the master branch with a couple of existing commits. Running the plain git log command prints the full history, but the default output is verbose.
Building a richer history view
The built-in help git help log lists many options. The four most useful ones for everyday browsing are:
--oneline— condense each commit to a single line.--graph— draw an ASCII graph showing how branches relate to each other.--decorate— show branch names, tags and HEAD next to commit IDs.--all— include the history of every branch in the repository, not only the current one.
Combined together they produce a compact graphical view of the whole project history:
git log --oneline --graph --decorate --all
That command is powerful but tedious to type. Git lets us create a personal shortcut called an alias: a new short command name that expands to a longer existing command. We register the alias globally so it works in every repository on the machine:
git config --global alias.hist "log --oneline --graph --decorate --all"
We can confirm the entry was saved by listing the global configuration with git config --global --list: the new alias.hist line appears at the bottom. From now on, typing git hist produces the exact same output as the long form. Aliases also let you pass additional parameters: for example, git hist coucou.html reuses the alias but limits the history to commits that touched the file coucou.html. Aliases are a simple but huge productivity boost once you build a small personal collection.
Summary
Learn how to master Git's log command with powerful formatting options like --oneline, --graph, and --all to visualize your commit history effectively. Discover Git aliases, a powerful feature that lets you create custom shortcuts for frequently-used commands, making your terminal workflow faster and more efficient by combining multiple options into a single command.
Key points
- Use 'git log --oneline' to display commits in a condensed, single-line format
- The '--graph' option provides a visual ASCII representation of your commit history and branching structure
- The '--all' flag shows the history of all available branches in your repository
- Create Git aliases using 'git config --global alias.<name> <command>' to define custom command shortcuts
- Aliases are stored at the global level (--global) so they work across all your repositories
- Aliased commands remain flexible — you can pass additional parameters to them just like the original command
FAQ
How do I combine multiple git log options into a single readable view?
Use 'git log --oneline --graph --all' to combine all three options: --oneline shows commits on one line, --graph visualizes the branch structure, and --all displays all branches. Then create an alias to save this as a custom command.
What is a Git alias and why should I use one?
A Git alias is a custom command that represents a longer or more complex Git command. Aliases shorten frequently-used commands in your terminal, saving time and reducing typos. For example, you can alias 'git log --oneline --graph --all' as 'git liste' for quick access.
How do I create and test a Git alias?
Use 'git config --global alias.<name> <command>' to create an alias, where <name> is your alias name and <command> is the full command. For example: 'git config --global alias.liste "log --oneline --graph --all"'. Then test it by typing 'git <aliasname>'. View all your aliases with 'git config --list'.