Configure Git: Name, Email, Editor, Default Branch and Aliases

Before your first commit, Git needs to know who you are and how you like to work. In this lesson you will configure Git once, the right way: identity, editor, default branch, line endings, useful defaults and time-saving aliases.

Advertisement

📖 What You’ll Learn: the system, global and local config levels, setting name and email, choosing an editor, the default branch name, line endings with core.autocrlf, useful extras, aliases, viewing and editing config, and credentials for GitHub.


đŸĒĒ Why Configure Git?

Every commit records who made it. Before your first commit, Git needs your name and email. A few more settings make Git friendlier: your favourite editor, the default branch name and how line endings are handled. You set these once per computer.


🧩 The Three Configuration Levels

LevelOptionApplies toStored in
System--systemEvery user on the computerGit’s installation folder
Global--globalAll repositories of your user account~/.gitconfig
Local--local (default inside a repo)One repository only.git/config in that repo

The most specific level wins: local overrides global, global overrides system. Most of the time you use --global.


👤 Step 1: Set Your Name and Email

git config --global user.name "Asha Verma"
git config --global user.email "asha.verma@example.com"

💡 Tip: Use the same email as your GitHub account (or GitHub’s private no-reply address, shown in GitHub Settings, Emails). That links your commits to your GitHub profile and contribution graph.

Need a different email for work repositories? Set it locally inside that repository:

cd path/to/work-repo
git config user.email "asha.verma@company.com"

📝 Step 2: Choose Your Editor

Git opens an editor for commit messages, merges and interactive rebases. Set VS Code:

git config --global core.editor "code --wait"

--wait tells Git to wait until you close the editor tab. Other options: "notepad" on Windows, "nano" on Linux and macOS.


đŸŒŋ Step 3: Default Branch Name

New repositories should start with main, matching GitHub:

git config --global init.defaultBranch main

â†Šī¸ Step 4: Line Endings

Windows and macOS/Linux use different line-ending characters, which can make every line look “changed” in a diff. Configure Git to normalize them:

# Windows
git config --global core.autocrlf true

# macOS and Linux
git config --global core.autocrlf input

For teams, a .gitattributes file in the repository (for example * text=auto) makes this consistent regardless of each person’s settings.


âš™ī¸ Step 5: Useful Extras

git config --global pull.rebase false         # git pull merges (default behaviour, avoids a warning)
git config --global push.autoSetupRemote true # first push of a new branch sets its upstream automatically
git config --global color.ui auto             # coloured output (usually already on)
git config --global fetch.prune true          # remove deleted remote branches on fetch

The pull and push options are explained in fetch vs pull and clone, push and pull.


âŒ¨ī¸ Step 6: Aliases (Shortcuts)

Save typing with 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"
git config --global alias.lg "log --oneline --graph --decorate --all"

Now git st runs git status and git lg shows a compact history graph.


🔍 View and Edit Your Configuration

git config --list                     # all settings
git config --list --show-origin       # settings and the file each comes from
git config user.email                 # one setting
git config --global --edit            # open ~/.gitconfig in your editor
git config --global --unset alias.co  # remove a setting

Your global file looks like this:

[user]
	name = Asha Verma
	email = asha.verma@example.com
[core]
	editor = code --wait
	autocrlf = true
[init]
	defaultBranch = main
[alias]
	st = status
	lg = log --oneline --graph --decorate --all

🔐 Credentials for GitHub over HTTPS

When you push over HTTPS, Git needs to authenticate with GitHub. Git for Windows and recent macOS setups use Git Credential Manager, which opens the browser once and stores the token securely. On Linux you can install Git Credential Manager or use SSH keys instead, covered in the next lesson.

âš ī¸ Common mistake: GitHub does not accept your account password for Git operations. Use Git Credential Manager, SSH keys or a personal access token.


📝 Assignment

  1. Set your global name, email, editor (VS Code), default branch (main) and line-ending setting.
  2. Run git config --list --show-origin and find which file each of your settings is stored in.
  3. Create the aliases st and lg, and test them later in your first repository.
  4. In any repository, set a local email and confirm with git config user.email that it overrides the global one.
  5. Open ~/.gitconfig with git config --global --edit and read through it.

❓ FAQ

🤔 How do I set my username and email in Git?

Run git config --global user.name "Your Name" and git config --global user.email "you@example.com". Check with git config --list.

🤔 How do I change the default branch name to main?

git config --global init.defaultBranch main. New repositories created with git init then start on main.

🤔 Where is the Git config file?

The global file is ~/.gitconfig in your home folder; each repository also has .git/config. Run git config --list --show-origin to see every file in use.

🤔 How do I set VS Code as the Git editor?

git config --global core.editor "code --wait".

🤔 What is core.autocrlf?

It controls line-ending conversion. Use true on Windows and input on macOS and Linux to avoid noisy diffs caused by different line endings.


đŸŽ¯ Next Steps

đŸŽŦ Learn Git and GitHub step by step: watch the series on YouTube!

Subscribe to SqaToolsByDY • Practice on sqatools.in

6 thoughts on “Configure Git: Name, Email, Editor, Default Branch and Aliases”

Leave a Comment