The Hook (The "Byte-Sized" Intro)
New laptop. Fresh OS install. You spend 30 minutes reconfiguring Git from memory — aliases, editor, defaults. Then you forget half of them. Dotfiles solve this: store your .gitconfig in a Git repo, symlink it on every machine, and your entire setup is one git clone away. Your config follows you everywhere.
📖 What is Sharing Configs?
Techniques for keeping your Git configuration consistent and portable across multiple machines, teams, and environments.
Conceptual Clarity
Approaches:
| Method | Portability | Team vs Personal |
|---|---|---|
| Dotfiles repo | ✅ Any machine | Personal |
| Git template | ✅ Auto-applies to new repos | Team |
| Committed .gitconfig | 🟡 Per-project | Team |
| Ansible/scripts | ✅ Automated provisioning | Team or Personal |
What to share:
| ✅ Safe to Share | ❌ Never Share |
|---|---|
| Aliases | Credentials / tokens |
| Editor settings | GPG private keys |
| Default branch | Passwords or secrets |
| Pull/push behavior | Personal paths |
| Color settings | Machine-specific paths |
Real-Life Analogy
Dotfiles are like carrying your favorite tool belt to every job site. Instead of borrowing unfamiliar tools each time, you bring your own and start working immediately.
Visual Architecture
Why It Matters
- Consistency: Same workflow on every machine — no missing aliases.
- Recovery: New machine setup in minutes, not hours.
- History: Git tracks changes to your config over time.
- Onboarding: New team members get a recommended config instantly.
Code
# ─── Method 1: Dotfiles repo (personal) ───
mkdir ~/dotfiles && cd ~/dotfiles
git init
cp ~/.gitconfig .gitconfig
git add . && git commit -m "Initial dotfiles"
# On new machine:
git clone https://github.com/you/dotfiles ~/dotfiles
ln -sf ~/dotfiles/.gitconfig ~/.gitconfig
# ─── Method 2: Git template (team) ───
# Create a template directory with shared hooks
mkdir -p ~/.git-templates/hooks
# Add pre-commit, commit-msg hooks here
git config --global init.templateDir ~/.git-templates
# Every new `git init` or `git clone` copies the template
# ─── Method 3: Project-level config ───
# Commit a .gitattributes and recommended config
echo "* text=auto eol=lf" > .gitattributes
# Document recommended settings in CONTRIBUTING.md
# ─── Safety: never share secrets ───
# Add to .gitignore in your dotfiles repo:
echo ".env" >> ~/dotfiles/.gitignore
echo "*.key" >> ~/dotfiles/.gitignoreKey Takeaways
- Store your
.gitconfigin a dotfiles repo for portability. - Use symlinks to connect the repo config to the system location.
- Never commit secrets — credentials, tokens, private keys.
- Use Git templates to share hooks and config with teams.
Interview Prep
-
Q: How do you keep Git config consistent across multiple machines? A: Store your
.gitconfigin a dotfiles repository. Clone it on each machine and create a symlink from~/.gitconfigto the repo copy. Changes are versioned and sync across machines. -
Q: What should you never share in a dotfiles repo? A: Credentials, API tokens, GPG private keys, and passwords. Use
.gitignorein the dotfiles repo to exclude them. Use tools likegit-credential-helperor secret managers instead. -
Q: How do you share Git hooks with a team? A: Use Git templates (
init.templateDir) to auto-install hooks on clone/init, or use a tool like Husky that installs hooks vianpm install.