GuideOctober 7, 20255 min read

How to Back Up and Restore Your Git Configuration

Your git aliases, commit signing, merge strategies, and global gitignore represent years of workflow refinement. Here's how to sync them everywhere.

What Lives in Your Git Config

Git configuration spans two key files that most developers customize over time:

  • ~/.gitconfig — aliases, user identity, core settings, diff/merge tools
  • ~/.gitignore_global — patterns ignored across all repositories

Together these files encode your entire Git workflow. Losing them means reconfiguring your identity, rewriting aliases, and re-specifying your preferred diff tool on every new machine.

Adding Git to ConfigSync

One command captures both files:

Add the Git module
configsync add module git

This tracks ~/.gitconfig and ~/.gitignore_global. Push to save them, pull on any new machine to restore:

Push and restore
configsync push -m "git config with aliases" # On new machine configsync pull

Template for Work vs Personal Email

If you use different Git identities for work and personal projects, ConfigSync templates let you set the right email based on machine tags:

~/.gitconfig with template
[user] name = Jane Developer {{#if tags contains "work"}} email = jane@company.com signingkey = WORK_GPG_KEY_ID {{else}} email = jane@personal.dev signingkey = PERSONAL_GPG_KEY_ID {{/if}} [commit] gpgsign = true [init] defaultBranch = main [core] editor = nvim excludesFile = ~/.gitignore_global

Tag your work machines with configsync tag add work and your personal machines without the tag. Each pull produces the correct .gitconfig for that machine. No more accidentally pushing commits with the wrong email.

Why this matters: Committing with the wrong email is one of the most common mistakes when setting up a new machine. ConfigSync templates eliminate this entirely. Your work laptop always gets your work email, your personal machine always gets your personal email.

Git Aliases Worth Syncing

Aliases are the highest-value part of a Git config. Here are some of the most commonly used aliases that are worth preserving across machines:

Useful aliases in .gitconfig
[alias] co = checkout br = branch st = status -sb lg = log --oneline --graph --decorate --all -20 undo = reset --soft HEAD~1 amend = commit --amend --no-edit wip = !git add -A && git commit -m "WIP" cleanup = !git branch --merged main | grep -v main | xargs -n 1 git branch -d recent = branch --sort=-committerdate --format='%(refname:short) %(committerdate:relative)'

Some developers accumulate dozens of aliases over years. Losing them and trying to remember the exact flags for lg or recent is painful. ConfigSync preserves all of them.

Global Gitignore

The global gitignore prevents OS and editor files from cluttering every repository:

~/.gitignore_global
# macOS .DS_Store .AppleDouble # Editors *.swp *.swo *~ .idea/ .vscode/ # Environment files .env.local .env.development.local # Dependencies (if not in .gitignore already) node_modules/ __pycache__/

Without this file synced, you end up with .DS_Store files in your commits on a new Mac until you remember to set it up again. ConfigSync makes sure it is always in place.

Syncing Global Git Hooks

Git supports a global hooks directory that applies to all repositories. This is useful for company-wide policies or personal automation:

Set up and sync global hooks
# Set the global hooks path in .gitconfig [core] hooksPath = ~/.config/git/hooks # Track the hooks directory configsync add directory ~/.config/git/hooks/

Common global hooks include pre-commit checks for secrets or large files, commit-msg hooks that enforce formatting conventions, and post-checkout hooks that run setup scripts. All of these travel with your ConfigSync snapshot.

Putting It All Together

The complete Git sync setup takes under a minute:

Complete setup
# Track .gitconfig and .gitignore_global configsync add module git # Track global hooks if you use them configsync add directory ~/.config/git/hooks/ # Tag work machines for email templating configsync tag add work # run on work machines only # Push configsync push -m "git config, gitignore, hooks" # On any new machine configsync pull

Every alias, every ignore pattern, every hook, and the correct email for each machine. Your Git workflow is fully portable.

Ready to try ConfigSync?

Sync your entire dev environment across machines in minutes. Free forever for up to 3 devices.