If you work with Git regularly, you know that git log
can be overwhelming, displaying a long list of commit hashes, authors, dates, and messages in a cluttered format.
To make your logs more readable and visually appealing, you can create a custom Git alias:
alias glp='git log --pretty=format:"%C(yellow)%h%Creset - %C(green)%an%Creset, %ar : %s"'
What This Alias Does:
Instead of the default git log
output, this alias presents commit history in a concise, color-coded format:
- %h → Shows the short commit hash in yellow.
- %an → Displays the author’s name in green.
- %ar → Indicates the commit time relative to now (e.g., "2 hours ago" or "3 days ago").
- %s → Displays the commit message.
Example Output:
Making the Alias Permanent
By default, the alias will only work in the current terminal session. Once you close the terminal, it will be lost. Follow these steps to make it permanent:
Step 1: Check Your Current Shell
Before adding the alias, check which shell you are using:
echo $SHELL
If the output is:
-
/bin/bash
→ You are using Bash. -
/bin/zsh
→ You are using Zsh.
This is important because the alias should be added to the correct configuration file.
Step 2: Add the Alias to the Correct File
✅ For Bash Users:
Edit the ~/.bashrc
file:
nano ~/.bashrc
Add the following line at the end of the file:
alias glp='git log --pretty=format:"%C(yellow)%h%Creset - %C(green)%an%Creset, %ar : %s"'
Save the file (CTRL + X
, then Y
, then Enter
).
✅ For Zsh Users:
Edit the ~/.zshrc
file:
nano ~/.zshrc
Add the alias at the end of the file:
alias glp='git log --pretty=format:"%C(yellow)%h%Creset - %C(green)%an%Creset, %ar : %s"'
Save the file (CTRL + X
, then Y
, then Enter
).
Step 3: Apply the Changes
For Bash, run:
source ~/.bashrc
For Zsh, run:
source ~/.zshrc
Step 4: Test the Alias
Now, run:
glp
If the alias works, you’ll see a clean and structured Git log output.
What If the Alias Still Doesn't Work?
If you are using Bash and see errors like command not found: shopt
, your ~/.bashrc
file might be corrupted.
To fix it, reset your Bash configuration:
mv ~/.bashrc ~/.bashrc.bak # Backup old file
cp /etc/skel/.bashrc ~/.bashrc # Restore default bashrc
source ~/.bashrc
Then, re-add the alias and try again.
Why Use This?
- Improved readability – No more overwhelming logs.
- Quick insights – Easily see who made a commit and when.
- Better debugging – Quickly locate specific changes.
By customizing your Git workflow with aliases like this, you can make working with Git much more efficient. 🚀
Try it out and streamline your Git experience!
Top comments (0)