Git Best Practices for Developers

Chapter 1 · Practice 4 of 4

Set your identity and a few helpful defaults once

From Commits and commit messages

Why it matters

A few settings, made once with git config --global, make every commit attributed correctly and remove small daily annoyances.

Use the same email as your GitHub or GitLab account so commits link to your profile.

SettingWhat it does
user.name, user.emailAttribute your commits correctly
init.defaultBranchNew repositories start with the branch name your team uses
push.autoSetupRemoteSets the upstream on your first push of a new branch
rerere.enabledGit remembers how you resolved a conflict and reuses the resolution next time

See the git-config documentation for every option.

Example

Shell
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git config --global push.autoSetupRemote true
git config --global rerere.enabled true