Topic · Foundations & Daily Workflow

Install & Configure Git

Before Git can protect your work, it needs to know two things: where it lives on your machine and how it should behave for you. This lesson gets Git installed, verified, and configured so your first commits are predictable instead of mysterious.

Install Git

Git is a command-line program. Many editors and desktop apps wrap it in buttons, but the program they call is still Git. Installing it once gives your terminal, editor, and hosting tools the same version-control engine.

Platform Common path Notes
Windows Install Git for Windows. This is the standard Windows distribution and normally includes Git Bash plus Git Credential Manager.
macOS Run git --version to trigger Xcode Command Line Tools, or install from git-scm.com. Package managers like Homebrew are also common when you want easier updates.
Linux Use your distribution package manager, such as apt or dnf. The exact package name varies; the Git book documents common commands.
Tip

If Git is already installed, update it before you start a serious project. Git is careful about backward compatibility, but newer releases improve defaults, security, credential tooling, and platform integration.

Verify the command

After installation, ask the shell which Git it can run. This catches the dull but common failure mode where Git exists on the computer but is not on the terminal's path.

terminalversion check
git --version

You should see a version string, such as git version 2.50.0. The exact number is not the point. The point is that your terminal can find Git and Git can start successfully.

PATH

Your PATH is the list of folders your shell searches when you type a command. If git --version says the command is not found, Git may be installed but not reachable from that shell session.

Understand config scope

Git configuration is layered. A setting can apply to the whole machine, to your user account, or to one repository. More specific settings win.

Scope Command flag When to use it
System --system Shared computers or managed machines. Usually requires administrator access.
Global --global Your normal personal defaults. Most first-time setup belongs here.
Local --local One repository. Use this when a project needs a different email, signing setup, or line-ending policy.

To inspect the combined result, include the origin file. This makes mysterious overrides much easier to diagnose.

terminalshow config and sources
git config --list --show-origin

Set your identity

Every commit records an author name and email address. Set these before your first commit so your history is attributable and hosting services can connect your commits to your account.

terminalglobal identity
git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Use the email address you want published in commit history. If you use GitHub and prefer privacy, use the no-reply email address GitHub provides for your account rather than inventing one.

Why this matters

Git commits are durable records. Changing your config later affects future commits, but it does not silently rewrite the author on commits you already made.

Choose defaults for new repositories

A little configuration now removes friction from every new repository you create. The three defaults worth setting early are the initial branch name, the editor Git launches for messages, and the way pulls reconcile divergent branches.

Initial branch name

When you run git init, Git creates the first branch. Set that default explicitly so new repositories start with the branch name you expect.

terminaldefault branch
git config --global init.defaultBranch main

Editor

Git opens an editor for commit messages, merge messages, tags, and other text you need to write carefully. Pick one you can actually exit under pressure.

terminaleditor examples
git config --global core.editor "code --wait"
# or:
git config --global core.editor "vim"
# or:
git config --global core.editor "nano"

Pull behavior

You do not need to master pulling yet, but it is useful to know that Git may ask how to reconcile local and remote work when histories diverge. Teams often choose a policy together. For a solo beginner, leaving this unset until the branching chapter is fine; do not copy a pull policy from the internet unless you understand the tradeoff.

Handle line endings

Text files end each line with invisible characters. Windows traditionally uses CRLF; macOS and Linux use LF. If collaborators use different systems, Git can normalize line endings so diffs show real code changes instead of every line as changed.

A reasonable first global setting is:

terminalline-ending defaults
# Windows
git config --global core.autocrlf true

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

For projects with mixed file types or stricter needs, prefer a repository-level .gitattributes file. That lets the project, rather than each developer's machine, state how text and binary files should be treated.

Careful

Changing line-ending settings in an existing repository can make many files appear modified. Commit or stash real work first, then refresh the repository deliberately.

Pick a credential strategy

Git itself can talk to remote servers, but authentication depends on the server and URL style. The two common routes are HTTPS with a credential manager, or SSH with a key.

Route Good fit What to know
HTTPS + credential manager Most beginners, especially on Windows or with GitHub CLI. Git Credential Manager can handle browser login, tokens, and two-factor authentication.
SSH key Developers comfortable managing keys or using many remotes. You create a key pair, add the public key to the host, and keep the private key private.

If you install Git for Windows, Git Credential Manager is usually included. On macOS and Linux, GitHub Docs recommend either GitHub CLI or Git Credential Manager for HTTPS workflows.

terminalinspect credential helper
git config --global credential.helper

Use Git help

Git's help system is part tutorial, part reference. When a command surprises you, ask Git what it thinks the command means before searching random answers.

terminalhelp commands
git help config
git config --help
git config -h

The long help forms open the manual page. The short -h form prints a compact command summary in the terminal. Use the short form when you need a flag name, and the manual when you need the model behind the flag.

First-time setup checklist

Here is a sane baseline for a new machine. Read the commands before running them, especially the values with names and email addresses.

Baseline commands

terminalfirst-time setup
git --version

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git config --global core.editor "code --wait"

# Choose the line-ending command for your operating system:
git config --global core.autocrlf true   # Windows
git config --global core.autocrlf input  # macOS or Linux

git config --list --show-origin

That last command is the check. It should show where each value came from. If you can explain your identity, default branch, editor, line-ending setting, and credential helper, your machine is ready for the next lesson.

Common pitfalls

Pitfall

Making commits before setting identity. Git will still create commits if it can infer something, but you may end up with the wrong name or email in history. Set user.name and user.email before your first project commit.

Pitfall

Setting everything with --global. Global is right for your normal defaults. It is wrong for project-specific identity, company-specific email, or repository-specific line-ending rules. Use local config when the project is the exception.

Pitfall

Ignoring line-ending churn. If a pull request shows every line changed, check line endings before reviewing the code. The real change may be hidden under formatting noise.

Pitfall

Saving passwords in plain text. Git has credential helpers for a reason. Prefer Git Credential Manager, GitHub CLI, your OS keychain, or SSH keys over storing credentials in scripts or shell history.

Worked examples

Example 1: Check whether Git is installed

Run the version command:

git --version

If you get a version string, continue to configuration. If the shell cannot find git, install Git or reopen the terminal after installation so PATH changes are loaded.

Example 2: Use a work email only for one repository

Keep your personal identity global, then override the email inside the work repository:

git config --global user.name "Avery Chen"
git config --global user.email "avery@example.com"

cd work-project
git config --local user.email "avery@company.example"

Local config lives in that repository's .git/config and wins over the global email only there.

Example 3: Make VS Code wait for commit messages

Git needs the editor process to stay open until you finish the message. For VS Code, that means including --wait:

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

Without the wait flag, Git may think you finished editing immediately and continue with an empty or aborted message.

Example 4: Diagnose a surprising config value

Suppose Git uses an email you did not expect. Ask Git for the value and its source:

git config user.email
git config --show-origin user.email
git config --list --show-origin

If the source is local, change it inside the repository. If it is global, update your user-level default.

Example 5: Prepare GitHub HTTPS authentication

First inspect whether a credential helper is configured:

git config --global credential.helper

If nothing is configured, install Git Credential Manager or use GitHub CLI's gh auth login flow. The first private clone or push should then open a secure browser-based login instead of asking you to paste a password into the terminal.

Sources & further reading

  • Installing Git Textbook Pro Git, 2nd Edition

    Canonical installation overview for Windows, macOS, Linux, and source builds.

  • First-Time Git Setup Textbook Pro Git, 2nd Edition

    The main reference for config scopes, identity setup, editor configuration, and help commands.

  • git-config Documentation Reference Git project

    Formal documentation for configuration variables such as init.defaultBranch, core.editor, and credential settings.

  • Practical guidance for choosing line-ending defaults across Windows, macOS, and Linux.

  • GitHub-specific guidance on GitHub CLI, Git Credential Manager, HTTPS authentication, and SSH alternatives.