Installing Git and First-Time Setup: Identity, Editor, Default Branch and Help
How to install Git on Windows, macOS and Linux, check the version, set your name and email, choose an editor and default branch name, see where each setting comes from, keep work and personal identities apart, and get help on any command.
kvi5hnuCode Sprout team member10 min readOn this page
Before the first commit, Git needs to be installed and told a few things about you. This article covers installation on each operating system, the settings every new user should make, and how to get help when you're unsure about a command. Article 33 goes much deeper into configuration. This one covers what you need on day one.
Is Git already installed?
Open a terminal (on Windows: PowerShell, Command Prompt, or the Git Bash window that Git for Windows installs) and run:
git --version
If it prints something like git version 2.56.1, Git is installed. On macOS and Linux, which git shows which program runs. If you get "command not found" or "is not recognized", install Git as described below. If the version is very old, more than a few years behind the current 2.56, update it: newer versions have better messages, safer defaults and commands this course uses, such as git switch and git restore (added in 2.23, 2019).
Installing Git
Windows
Download Git for Windows from git-scm.com, or install it from a terminal with winget install --id Git.Git -e. The installer asks several questions. The defaults are sensible, with two worth checking:
- Default editor: the installer offers Vim first. If you don't know Vim, pick an editor you know, such as Notepad or VS Code. You can change it later (see below).
- Line endings: the recommended option, "Checkout Windows-style, commit Unix-style line endings", sets
core.autocrlf=true. Article 35 explains what that means.
Git for Windows includes Git Bash, a Unix-style shell. The commands in this course work as written there. In PowerShell they mostly work too, but quoting rules differ: use double quotes around arguments with spaces, and in Command Prompt quote arguments that contain ^, which is an escape character there (git show "HEAD^").
macOS
macOS offers to install Apple's command-line developer tools, which include Git, the first time you run git. You can also run xcode-select --install. Apple's Git works, but it usually lags a few versions behind. Its version string ends in something like (Apple Git-155). For the current release, install Git with Homebrew:
brew install git
Linux
Use your distribution's package manager:
sudo apt install git # Debian, Ubuntu
sudo dnf install git # Fedora, RHEL
sudo pacman -S git # Arch
sudo apk add git # Alpine
Long-term-support distributions can ship an old version. On Ubuntu, the Git maintainers' PPA has the latest release: sudo add-apt-repository ppa:git-core/ppa, then sudo apt update and sudo apt install git.
From source
Building from source gives you any version you want. Install a C compiler and the development packages for curl, expat, OpenSSL and zlib, download a release tarball from kernel.org/pub/software/scm/git/, then:
make prefix=/usr/local all
sudo make prefix=/usr/local install
The sandbox that runs this course's examples was built this way, from the Git 2.56.1 source.
Tell Git who you are
Every commit records an author name and email. Set them once, for all your repositories, with --global:
git config --global user.name "Ana Diaz"
git config --global user.email "ana@example.com"
The quotes around Ana Diaz are needed because the value contains a space. These settings are not a login. They're just text stored in each commit. Signing in to GitHub or another server is a separate step (article 21). Two consequences:
- Use the email address your hosting service knows, so it can link your commits to your account. GitHub also offers a private
noreplyaddress if you don't want your real email in public history. - Anyone can put any name in a commit. Article 39 shows how signed commits prove who made them.
Two more settings for day one
The default branch name. A new repository starts with one branch. Git's built-in default is still master, and Git 3.0 will change it to main. Most hosting services already use main. Choose a name now, and Git stops printing its reminder hint on every git init:
git config --global init.defaultBranch main
Your editor. Git opens an editor when it needs text from you: a commit message written without -m, an interactive rebase, a merge message. If you've never used Vim, Git's usual default, set something you know:
git config --global core.editor "nano"
git config --global core.editor "code --wait" # VS Code
git config --global core.editor "notepad" # Windows Notepad
Graphical editors need a "wait" option, such as VS Code's --wait, so the command doesn't return until you close the file. Without it, Git sees an empty file immediately and stops with "Aborting commit due to empty commit message."
Git chooses the editor in this order: the GIT_EDITOR environment variable, then the core.editor setting, then the VISUAL and EDITOR environment variables, then the compiled-in default, usually vi. So GIT_EDITOR=nano git commit uses nano for one command only, whatever the configuration says. git var GIT_EDITOR shows which editor Git would use.
Seeing your settings, and where they come from
Git reads settings from several files. The three you'll meet most are:
| Level | Option | File | Applies to |
|---|---|---|---|
| system | --system | /etc/gitconfig (inside the Git install folder on Windows) | every user on the computer |
| global | --global | ~/.gitconfig (or ~/.config/git/config) | all your repositories |
| local | --local, the default inside a repository | .git/config in the repository | that one repository |
A setting in a more specific file wins: local beats global, and global beats system. The example sets a global identity and editor, shows the file Git wrote, and then overrides the email for one repository:
git config --global user.name "Ana Diaz"
git config --global user.email "ana@example.com"
git config --global init.defaultBranch main
git config --global core.editor nano
echo "--- the global config file"
cat ~/.gitconfig
echo "--- every setting, with the file it came from"
git config list --show-origin
echo "--- the editor Git will use"
git var GIT_EDITOR
echo "--- a work repository with its own email"
git init -q work-project
cd work-project
git config user.email "ana.diaz@company.example"
git config list --show-scope | grep user
git config get user.email
--- the global config file
[user]
name = Ana Diaz
email = ana@example.com
[init]
defaultBranch = main
[core]
editor = nano
--- every setting, with the file it came from
file:/etc/gitconfig user.name=Sam Lee
file:/etc/gitconfig user.email=sam@example.com
file:/etc/gitconfig init.defaultbranch=main
file:/tmp/home/.gitconfig user.name=Ana Diaz
file:/tmp/home/.gitconfig user.email=ana@example.com
file:/tmp/home/.gitconfig init.defaultbranch=main
file:/tmp/home/.gitconfig core.editor=nano
--- the editor Git will use
nano
--- a work repository with its own email
system user.name=Sam Lee
system user.email=sam@example.com
global user.name=Ana Diaz
global user.email=ana@example.com
local user.email=ana.diaz@company.example
ana.diaz@company.example
The sandbox has a system-level identity (Sam Lee), so user.name appears twice in the listing. Git uses the last one it reads, from the most specific file: the global Ana Diaz. In work-project, the local user.email overrides the global one, while user.name still comes from the global file. git config get prints the value that wins.
git config list, get, set and unset are subcommands added in Git 2.46 (2024). The older forms still work and are what you'll see in most guides: git config --list, git config user.email to read a value, git config user.email "..." to set one, and git config --unset user.email. git config --global --edit (or git config edit --global) opens the file in your editor.
Keeping work and personal identities apart
If you commit to work and personal projects from the same computer, a single global email is easy to get wrong. Two safety nets:
Require an identity in each repository. With user.useConfigOnly, Git refuses to guess an identity from your login and computer name, so it commits only with a configured name and email. With no global email set, each repository then needs its own user.email, which is the point of this setup:
export GIT_CONFIG_NOSYSTEM=1 # ignore the sandbox's system-wide identity, for this demo
git config --global init.defaultBranch main
git config --global user.useConfigOnly true
git init -q side-project
cd side-project
echo "notes" > notes.txt
git add notes.txt
git commit -m "Add notes"
echo "--- after setting an identity for this repository"
git config user.name "Ana Diaz"
git config user.email "ana@example.com"
git commit -m "Add notes"
git log -1 --format='Author: %an <%ae>'
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: no email was given and auto-detection is disabled
--- after setting an identity for this repository
[main (root-commit) 1c1855a] Add notes
1 file changed, 1 insertion(+)
create mode 100644 notes.txt
Author: Ana Diaz <ana@example.com>
Choose the identity by folder. A conditional include in ~/.gitconfig loads extra settings for every repository under a folder, so everything under ~/work/ gets the work email automatically:
# ~/.gitconfig
[user]
name = Ana Diaz
email = ana@example.com
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
# ~/.gitconfig-work
[user]
email = ana.diaz@company.example
The trailing / in gitdir:~/work/ matters: it means "this folder and everything below it". Article 33 covers conditional includes in detail, including matching on the remote URL instead of the folder.
Getting help
Every command has a full manual page and a short summary:
git help commit # the full manual (the same as: git commit --help)
git commit -h # a short list of the options, in the terminal
git help -a # every command
git help -g # concept guides, such as the glossary and everyday workflows
The full manual opens in a pager or browser, depending on your system: on Windows it opens in a browser, and elsewhere in man. The same pages are online at git-scm.com/docs. In the course sandbox, only -h works, because no manual viewer is installed.
When you mistype a command, Git suggests the closest match:
git init -q demo
cd demo
git stauts
echo "--- with help.autocorrect set to immediate"
git config help.autocorrect immediate
git stauts
git: 'stauts' is not a git command. See 'git --help'.
The most similar command is
status
--- with help.autocorrect set to immediate
WARNING: You called a Git command named 'stauts', which does not exist.
Continuing under the assumption that you meant 'status'.
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)
help.autocorrect controls what happens when exactly one command is a close match:
| Value | Behaviour |
|---|---|
0, false or show (the default) | show the suggestion only |
1, true or immediate | run the suggested command straight away |
| a number above 1 | run it after that many tenths of a second, so 20 waits 2 seconds, giving you time to press Ctrl+C |
prompt | ask before running it |
never | don't suggest anything |
A bigger mistake, such as git testingit, simply reports that the command doesn't exist.
What's current
- Git 2.56.1 (October 2026) is the current release. Git for Windows, Homebrew and most rolling distributions follow new releases within days.
git configsubcommands (list,get,set,unset,rename-section,remove-section,edit) arrived in Git 2.46. The older option-style forms are deprecated but still work.- Git 3.0 will make
mainthe default branch name. Settinginit.defaultBranchnow means nothing changes for you when it arrives. help.autocorrectacceptstrueandimmediateas synonyms for running immediately, and since Git 2.491means "immediately" rather than "after a tenth of a second".
Common questions
I set the wrong name or email and already made commits. What now?
Fix the setting first, so new commits are right. For the most recent commit, git commit --amend --reset-author --no-edit rewrites it with your corrected identity (article 6). For older commits that haven't been shared, an interactive rebase can fix them (article 15). For shared history, see article 47, and consider leaving it: rewriting shared commits causes trouble for everyone who has them.
Do user.name and user.email need to match my GitHub account?
The email should be one your hosting service has on file, such as a verified address or the service's noreply address, so it can link commits to your profile. The name can be anything: it's display text.
Where is my global config file on Windows?
%USERPROFILE%\.gitconfig, usually C:\Users\<you>\.gitconfig. git config list --show-origin shows the exact path of every file Git reads, on any system.
Why does git commit open a strange screen I can't get out of?
That's Vim, the default editor. Type :q! and press Enter to quit without saving, which aborts the commit, or press i, type the message, press Esc, then type :wq and press Enter to save. Then set an editor you know with core.editor.
What does "Author identity unknown" mean?
Git has no user.name or user.email to record, or no identity is configured at any level and user.useConfigOnly stops Git guessing one. Set them with git config --global (or without --global for just this repository) and commit again.
Summary
- Install Git with Git for Windows, Homebrew on macOS, or your Linux package manager.
git --versionshows what you have. - Set
user.nameanduser.emailwithgit config --globalbefore your first commit. They're recorded in every commit and have nothing to do with logging in. - Set
init.defaultBranch mainand acore.editoryou know. Graphical editors need a wait option, such ascode --wait. - Settings live at system, global and local levels. The most specific wins, and
git config list --show-originshows where each comes from. user.useConfigOnlyandincludeIfhelp keep work and personal identities apart.git help <command>opens the manual, and<command> -hprints a short option list.
Practice questions
You set your global email to ana@example.com, but commits in one repository come out as ana.diaz@company.example. What's the most likely reason, and how do you confirm it?
Answer
That repository has its own user.email in .git/config, which overrides the global value. Run git config list --show-origin (or git config get --show-origin user.email) inside the repository: it shows the local file supplying the value. Remove it with git config unset user.email to fall back to the global email, or keep it if the override is intended.
A teammate sets core.editor to code, without --wait. Every git commit without -m fails with "Aborting commit due to empty commit message." Why?
Answer
The code command opens the file in VS Code and returns immediately, without waiting for you to finish. Git reads the message file as soon as the editor command returns, finds it empty, and aborts. code --wait makes the command wait until the file's tab is closed, so Git reads the finished message.
What does this print, and why?
git config --global core.editor nano
GIT_EDITOR=vim git var GIT_EDITOR
Answer
It prints vim. The GIT_EDITOR environment variable takes priority over the core.editor setting, and here it's set for that one command. Without it, git var GIT_EDITOR would print nano.
Previous: What Git Is: Version Control, Snapshots and Distributed Repositories
Next: Your First Git Repository: init, add, commit, status and log

More in Git Course
Quiz: Git Delicate Details
Twenty-five questions on Git's subtle corners: what commit -a and stash leave out, empty folders, ignore patterns and negation, HEAD~ versus HEAD^, ours and theirs in a rebase, tags that don't move or don't push, describe, merge reverts, diff exit codes, stash conflicts and more.
Quiz: Git Interview Questions
Thirty Git questions of the kind asked in developer interviews: Git versus GitHub, the staging area, merge versus rebase, fetch versus pull, reset, revert and restore, detached HEAD, conflicts, force pushing, stash, cherry-pick, reflog, bisect, submodules, LFS and how commits are identified.
Quiz: Git Course Final Exam (All Parts)
The final exam for the Git course: thirty questions across all twelve parts, from the three areas and staging through branching, remotes, undoing, history investigation, configuration, tags, larger projects, patches, rewriting, internals and troubleshooting.
Quiz: Professional Git Practice (Git Part 12)
Sixteen questions on migrating to Git from Subversion, TFVC and Mercurial, team best practices for commits, branches and reviews, repository hygiene, and diagnosing and fixing the most common Git errors, with explanations.
Discussion
Sign in to ask a question or share what you learned.