DevOps · Infrastructure as Code (IaC) · Git Series – Part 2
Git configuration is essential before you make your first commit. Git needs to know who you are and how you want it to behave. This step is essential whether you are a developer, DevOps engineer, cloud engineer, or anyone working with code or IaC.
In this chapter, you will learn:
- What Git configuration is
- How to set username and email (global & local)
- How to view and edit Git settings
- How to set a default editor
- How to create powerful Git aliases
- How configuration is stored
- Troubleshooting
Table of Contents
1. Understanding Git Configuration
Git settings follow a clear hierarchy:
- System (
/etc/gitconfig) — applies to all users - Global (
~/.gitconfig) — applies to your user profile - Local (
<project>/.git/config) — applies only to a single repository
Local overrides global, and global overrides system.
2. Configure Your Username and Email
Every commit you make contains author information. Git must know who you are.
🔹 Set Global Username & Email
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
🔹 Set Local Username & Email (only for current repo)
git config --local user.name "Project User"
git config --local user.email "[email protected]"
🔹 Verify your configuration
git config --list
3. Set Your Default Code Editor
By default, Git may open an editor you don’t prefer.
Popular choices:
VS Code
git config --global core.editor "code --wait"
Nano
git config --global core.editor "nano"
Vim
git config --global core.editor "vim"
4. Useful Git Aliases (Highly Recommended)
Aliases help you run long commands using short shortcuts.
🔹 Basic Aliases
git config --global alias.st "status"
git config --global alias.co "checkout"
git config --global alias.br "branch"
git config --global alias.cm "commit -m"
🔹 Log Aliases (beautiful logs)
git config --global alias.lg "log --oneline --graph --all"
git config --global alias.l "log --decorate --oneline --graph"
🔹 Undo / Fix Aliases
git config --global alias.unstage "reset HEAD --"
git config --global alias.last "log -1 HEAD"
🔹 Stash Aliases
git config --global alias.ss "stash save"
git config --global alias.sl "stash list"
git config --global alias.sa "stash apply"
5. How Git Stores Configuration
Git stores settings in three files:
System Level
/etc/gitconfig
Global Level
~/.gitconfig
Local Level (inside repo)
<repo>/.git/config
To open .gitconfig directly:
code ~/.gitconfig
6. Example .gitconfig File (Ready to Use)
[user]
name = Your Name
email = [email protected]
[core]
editor = code --wait
autocrlf = input
[alias]
st = status
co = checkout
br = branch
cm = commit -m
lg = log --oneline --graph --all
unstage = reset HEAD --
last = log -1 HEAD
Copy → Paste → Done. ✔️
7. Git Configuration Troubleshooting
❗ “fatal: unable to auto-detect email address”
You forgot to configure username/email.
Fix:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
❗ VS Code: “code: command not found”
VS Code CLI is not added to PATH.
Windows:
Use Command Palette → Shell Command: Install ‘code’ command in PATH
❗ Editor opens but doesn’t close
Some editors require a specific exit command:
- Vim:
:wq - Nano:
Ctrl + X, thenY, then Enter
Git Configuration Best Practices & Key Takeaways
Proper Git configuration is the foundation of a smooth development workflow. Whether you’re working on solo projects or collaborating with large teams, mastering Git configuration saves time and prevents common mistakes. Here are the most important takeaways from this guide:
Setting up your identity correctly ensures that every commit is properly attributed to you, which is critical for team collaboration and code review processes. Your git configuration acts as your digital signature in version control history.
Using aliases dramatically improves your productivity by reducing the time spent typing long Git commands. These shortcuts become muscle memory and help you work more efficiently in daily development tasks.
Understanding configuration hierarchy (system, global, and local levels) gives you flexibility in managing different settings across projects, allowing for custom configurations when needed for specific repositories while maintaining consistency across your development environment.
8. What’s Next?
Now that your Git environment is properly configured, you’re ready to start working with files and tracking changes.
➡️ In the next chapter:
“Git Get Started – Creating your first repo, adding files, and making your first commit.”
You’ll learn how to:
✔ create repositories
✔ add new files
✔ stage changes
✔ commit your work
✔ view history