The Archivist's Tools
Aliases, hooks, and Git configuration
The Master Archivist invites you into a room you had never seen - his personal workshop. The walls are covered with shelves loaded with enchanted quills, self-correcting scrolls, and strange mechanisms that seem to work on their own. Inkwells close by themselves, stamps automatically check every written line, and magical shortcuts glow on a desk worn by years of use.
"You have mastered the Ancient Arts - suspended time, divination, protective seals. But a true Master Archivist does not simply know the techniques. They forge their own tools. Today, I open my workshop to you. You will create shorthand incantations that speed up your work, guardian quills that automatically check every scroll, and you will customize your workstation so it becomes an extension of yourself."
Git aliases - Shorthand incantations
Some Git commands are long to type and you use them dozens of times a day. Aliases let you create personalized shortcuts.
Creating aliases
The syntax is simple:
git config --global alias.SHORTCUT "COMMAND" Here are the most common aliases:
# Status shortcut
git config --global alias.st status
# Checkout shortcut
git config --global alias.co checkout
# Branch shortcut
git config --global alias.br branch
# Commit shortcut
git config --global alias.ci commit
# Log with graph - the most useful!
git config --global alias.lg "log --oneline --graph --all" Using aliases
Once configured, you can use them immediately:
# Instead of "git status"
git st
# Instead of "git checkout main"
git co main
# Instead of "git branch"
git br
# Instead of "git commit -m 'message'"
git ci -m "message"
# Instead of "git log --oneline --graph --all"
git lg Checking existing aliases
# View all configured aliases
git config --get-regexp alias "Master Archivists don't waste their time writing out full formulas when a power word will do. Every second saved is another second for reflection."
Git hooks - The guardian quills
Hooks are scripts that execute automatically at key moments in the Git workflow. They are silent guardians that check, validate, and protect your work.
Where do hooks live?
Every Git repository contains a .git/hooks/ folder with hook examples:
ls .git/hooks/ You will see files like pre-commit.sample, commit-msg.sample, etc. To activate a hook, simply create a file with the right name (without .sample) and make it executable.
The most useful hooks
| Hook | When it runs | Common usage |
|---|---|---|
pre-commit | Before each commit | Linting, style checks, quick tests |
commit-msg | After the message is entered | Validate commit message format |
pre-push | Before each push | Full tests, security checks |
post-merge | After a merge | Install dependencies, clear cache |
Creating a pre-commit hook
A hook is simply a script. Here is an example that checks for the presence of "TODO" in staged files:
#!/bin/bash
# .git/hooks/pre-commit
# Checks that no staged file contains "TODO"
files=$(git diff --cached --name-only)
if [ -z "$files" ]; then
exit 0
fi
if git diff --cached --diff-filter=ACM | grep -q "TODO"; then
echo "WARNING: One or more files contain 'TODO'!"
echo "Affected files:"
git diff --cached --name-only | while read f; do
if git show ":$f" 2>/dev/null | grep -q "TODO"; then
echo " - $f"
fi
done
echo ""
echo "The commit is allowed, but remember to handle these TODOs."
fi
exit 0 Important: The hook must be executable! Without that, Git will silently ignore it.
chmod +x .git/hooks/pre-commit Creating a commit-msg hook
This hook checks that the commit message meets a minimum format:
#!/bin/bash
# .git/hooks/commit-msg
# Rejects commit messages shorter than 10 characters
message=$(cat "$1")
length=${#message}
if [ "$length" -lt 10 ]; then
echo "REJECTED: Commit message is too short ($length characters)."
echo " Minimum required: 10 characters."
echo " Message received: \"$message\""
exit 1
fi
exit 0 chmod +x .git/hooks/commit-msg "The guardian quills are the Archivist's most faithful allies. They never sleep, never tire, and catch errors before they become problems. A workshop without guardians is a vulnerable workshop."
Advanced Git configuration
Beyond aliases and hooks, Git offers many configuration options that improve your comfort at work.
The default editor
# Visual Studio Code
git config --global core.editor "code --wait"
# Vim
git config --global core.editor "vim"
# Nano (the simplest)
git config --global core.editor "nano" The --wait option for VS Code is important: it tells Git to wait until you close the file before continuing.
The default branch
git config --global init.defaultBranch main All your new repositories will use main instead of master as the default branch.
Pull behavior
# Rebase instead of merge on pull (recommended)
git config --global pull.rebase true
# Or force classic merge
git config --global pull.rebase false With pull.rebase true, a git pull will automatically rebase instead of creating a merge commit. This keeps the history cleaner.
Conflict style
git config --global merge.conflictstyle diff3 The diff3 style adds an extra section in merge conflicts: in addition to "the left version" and "the right version", you also see the original common version. This makes it much easier to understand what changed on each side.
<<<<<<< HEAD
Your branch version
||||||| merged common ancestors
Original version (before both modifications)
>>>>>>> feature
Other branch version The .gitconfig file - The big picture
All these configurations are stored in a ~/.gitconfig file (on Linux/macOS) or C:\Users\YOUR_NAME\.gitconfig (on Windows).
You can view it directly:
# View the full configuration
git config --global --list
# Or open the file in your editor
git config --global --edit The file looks like this:
[user]
name = Your Name
email = your@email.com
[alias]
st = status
co = checkout
br = branch
ci = commit
lg = log --oneline --graph --all
[core]
editor = code --wait
[init]
defaultBranch = main
[pull]
rebase = true
[merge]
conflictstyle = diff3 Practical exercise - Forge your tools
Forge your own Archivist's tools:
- Create an
archivists-toolsrepository - Configure the aliases
st,co,br,ci, andlg - Test the aliases with git st and git lg
- Create a
pre-commithook that detects "TODO"s - Test it by committing a file containing "TODO"
- Create a
commit-msghook that rejects short messages - Test it with a bad then a good message
- Run the verification script
Step 1 - Create the repository
mkdir archivists-tools
cd archivists-tools
git init -b main Step 2 - Configure the aliases
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.lg "log --oneline --graph --all" Step 3 - Test the aliases
# Verify that the aliases work
git st
git lg git st should display the repository status and git lg should display the graph (empty for now).
Step 4 - Create the pre-commit hook
cat > .git/hooks/pre-commit << 'HOOK'
#!/bin/bash
# pre-commit hook: warns if staged files contain "TODO"
files=$(git diff --cached --name-only)
if [ -z "$files" ]; then
exit 0
fi
if git diff --cached --diff-filter=ACM | grep -q "TODO"; then
echo "WARNING: One or more files contain 'TODO'!"
echo "Affected files:"
git diff --cached --name-only | while read f; do
if git show ":$f" 2>/dev/null | grep -q "TODO"; then
echo " - $f"
fi
done
echo ""
echo "The commit is allowed, but remember to handle these TODOs."
fi
exit 0
HOOK Make it executable:
chmod +x .git/hooks/pre-commit Step 5 - Test the pre-commit hook
echo "# Task list" > tasks.txt
echo "TODO: Add validation" >> tasks.txt
git add tasks.txt
git commit -m "Add the task list with TODO" You should see the hook's warning before the commit is created.
Step 6 - Create the commit-msg hook
cat > .git/hooks/commit-msg << 'HOOK'
#!/bin/bash
# commit-msg hook: rejects messages shorter than 10 characters
message=$(cat "$1")
length=${#message}
if [ "$length" -lt 10 ]; then
echo "REJECTED: Commit message is too short ($length characters)."
echo " Minimum required: 10 characters."
echo " Message received: \"$message\""
exit 1
fi
exit 0
HOOK Make it executable:
chmod +x .git/hooks/commit-msg Step 7 - Test the commit-msg hook
First, test with a message that is too short (it should be rejected):
echo "Testing the commit-msg hook" > test-hook.txt
git add test-hook.txt
git commit -m "test" The commit should be rejected because "test" is fewer than 10 characters.
Now try again with a proper message:
git commit -m "Add the test file for hooks" This time, the commit should go through.
Step 8 - Run the verification
bash verifier.sh .\verifier.ps1 Command summary
| Command | Description |
|---|---|
git config --global alias.XX "cmd" | Create an alias |
git config --get-regexp alias | List aliases |
git config --global core.editor "editor" | Change the editor |
git config --global init.defaultBranch main | Default branch |
git config --global pull.rebase true | Pull in rebase mode |
git config --global merge.conflictstyle diff3 | Enhanced conflict style |
git config --global --list | View the full configuration |
chmod +x .git/hooks/hook-name | Make a hook executable |
The Master Archivist looks at your freshly forged tools with a rare smile - barely perceptible.
"You have created your own shorthand incantations and your own guardian quills. You have customized your workshop so it works with you, not against you. That is the mark of a true craftsman."
He slowly rises and unhooks an ancient badge from the wall - a golden scroll surrounded by gears, the symbol of the Master Archivists.
"The Arc of the Ancient Arts is complete. You now master suspended time, code divination, protective seals, and tool forging. You are no longer an apprentice nor a journeyman. You are a Master Archivist."
He pins the badge on your cloak. Then he leads you toward an immense metal door, covered with gears and steam pipes. From the other side, you hear the rumble of titanic machines.
"But the world is changing, Master Archivist. Beyond this door lie the Automatic Forges - machines capable of testing, building, and deploying your code automatically, without human intervention. CI/CD, pipelines, GitHub Actions... That is the next chapter of your story. And it will be extraordinary."