How to Install Git on Windows: Git for Windows, winget and Setup
Git does not ship with Windows. You install it through Git for Windows, the official distribution that bundles the Git binaries with a Unix-like shell, a credential helper and supporting tools.
There are two supported ways to get it: the winget package manager, or the installer downloaded from
the Git website. Both install the same software.
Step 1 — Check whether Git is already installed
Section titled “Step 1 — Check whether Git is already installed”Open PowerShell or Windows Terminal and run:
git --versionWhat it doesPrints the version of Git currently on your PATH.
Why we run itSome development tools bundle Git, so it may already be present. Checking first avoids installing a second copy.
Expected resultA line beginning git version. On Windows it usually includes a Windows-specific suffix, for example git version 2.55.0.windows.1.
If Git is not installed, PowerShell reports:
git : The term 'git' is not recognized as the name of a cmdlet, function, script file, or operable program.Continue to the next step.
Step 2 — Install Git for Windows
Section titled “Step 2 — Install Git for Windows”Choose one of these. They install the same distribution.
winget is Microsoft’s package manager, included with current Windows 10 and Windows 11 installations.
winget install --id Git.Git -e --source wingetThe flags matter:
--id Git.Gitselects the package by its exact identifier rather than by a fuzzy name match.-erequires an exact match, so a differently named package cannot be substituted.--source wingetrestricts the search to the official winget repository.
winget downloads the installer and runs it silently with sensible defaults. When it finishes, open
a new terminal — the current session will not have the updated PATH.
To upgrade later:
winget upgrade --id Git.Git -e- Go to git-scm.com/install/windows.
- Download the standalone installer for your architecture — 64-bit for most machines, ARM64 for Windows on ARM devices such as Copilot+ PCs.
- Run the downloaded
.exeand work through the setup wizard. The defaults are well chosen; see installer choices below for the three worth understanding.
This route is the one to use on a machine without winget, or when you want to review the options
rather than accept defaults.
Step 3 — Verify the installation
Section titled “Step 3 — Verify the installation”In a new terminal:
git --versiongit version 2.55.0.windows.1To see where the executable actually lives:
Get-Command git | Select-Object -ExpandProperty SourceA default installation puts it under C:\Program Files\Git\.
Installer choices that matter
Section titled “Installer choices that matter”If you used the graphical installer, three of its screens are worth understanding. If you used
winget, it chose sensible defaults for all three and you can change them later with git config.
Default editor
Section titled “Default editor”The installer offers a list including Vim, Nano, Notepad++ and Visual Studio Code. Vim is the historical default and is difficult to leave if you have not used it. Pick something you can exit. Notepad or VS Code are both reasonable.
Adjusting your PATH environment
Section titled “Adjusting your PATH environment”Three options are offered. The recommended middle option — “Git from the command line and also from
3rd-party software” — adds Git to the system PATH so it works in PowerShell, Command Prompt and
Windows Terminal, without adding the entire suite of bundled Unix tools. Take it unless you have a
specific reason not to.
Line ending conversions
Section titled “Line ending conversions”This is the option that causes real problems if set carelessly, and it is covered in full below.
Step 4 — Choose your terminal
Section titled “Step 4 — Choose your terminal”Git for Windows installs Git Bash, and Windows already provides PowerShell and Command Prompt. Understanding what each gives you saves confusion later.
| Shell | What it is | Notes |
|---|---|---|
| Git Bash | A Bash shell bundled with Git for Windows | Unix-style commands (ls, cat, grep); paths look like /c/Users/you |
| PowerShell | Windows’ modern shell | Full Git support; Windows-style paths; better for Windows tooling |
| Command Prompt | The legacy Windows shell | Works, but has the fewest conveniences |
| Windows Terminal | A terminal application, not a shell | Hosts any of the above in tabs; the recommended way to run all of them |
Every Git command in this curriculum works identically in all three shells. Git Bash is useful when you are following documentation written for Linux or macOS, because the surrounding shell commands match too.
Step 5 — Configure your identity
Section titled “Step 5 — Configure your identity”Git records an author name and email on every commit and will not commit until they are set.
-
Set your name.
Terminal window git config --global user.name "Your Name" -
Set your email.
Terminal window git config --global user.email "you@example.com" -
Confirm both.
Terminal window git config --global --list
Step 6 — Set the default branch name
Section titled “Step 6 — Set the default branch name”git config --global init.defaultBranch mainWithout this, git init creates a branch named master and prints a hint recommending you configure
a default. Setting main matches current convention on every major hosting platform.
Step 7 — Choose an editor
Section titled “Step 7 — Choose an editor”git config --global core.editor "code --wait"--wait is required. Without it, code returns immediately and Git receives an empty commit message.
git config --global core.editor notepadAlways available. Save and close the window to complete the commit.
git config --global core.editor "vim"Write and quit with :wq. Abort with :q!, which cancels the commit.
Line endings: the Windows-specific issue
Section titled “Line endings: the Windows-specific issue”This is the one genuinely Windows-specific Git topic, and understanding it prevents a class of confusing diffs.
Windows text files traditionally end lines with a carriage return plus a line feed (CRLF). Linux and
macOS use a line feed alone (LF). Git stores file content byte for byte, so a file committed with
CRLF endings differs from the same file committed with LF endings — even when the visible text is
identical.
On a mixed-platform team, that produces diffs showing every line as changed when nothing meaningful was edited.
Git’s answer is the core.autocrlf setting:
| Value | On checkout | On commit | Suits |
|---|---|---|---|
true | LF → CRLF | CRLF → LF | Windows |
input | No conversion | CRLF → LF | macOS and Linux |
false | No conversion | No conversion | Repositories that manage this themselves |
Git for Windows sets core.autocrlf=true by default, which is the right choice for Windows. Files are
stored in the repository with LF and appear in your working tree with CRLF. Check yours:
git config --get core.autocrlfCredential Manager
Section titled “Credential Manager”Git for Windows bundles Git Credential Manager (GCM), and the installer enables it by default. GCM stores credentials in Windows Credential Manager — the operating system’s encrypted credential store — rather than in a plain-text file, and it handles browser-based and multi-factor authentication flows for the major hosting providers.
Check that it is configured:
git config --get credential.helpermanagerIf that returns nothing, enable it:
git config --global credential.helper managerThe first time you push to an HTTPS remote, GCM opens a browser window to authenticate. After that, credentials are retrieved from the Windows credential store automatically.
To clear a stored credential — after rotating a token, for example — open Credential Manager from the Windows Control Panel, select Windows Credentials, and remove the entry for the host.
Inspecting your configuration
Section titled “Inspecting your configuration”git config --list --show-scope --show-originThis prints every setting with the scope and file it came from. On Windows the three scopes resolve to:
| Scope | Typical location |
|---|---|
| System | C:\Program Files\Git\etc\gitconfig |
| Global | C:\Users\<you>\.gitconfig |
| Local | .git\config inside the repository |
Local overrides global, and global overrides system.
Troubleshooting
Section titled “Troubleshooting”git is not recognised after installing. Open a new terminal. If it still fails, confirm Git is on
the PATH:
$env:PATH -split ';' | Select-String 'Git'If nothing matches, re-run the installer and choose the recommended PATH option.
Every line shows as changed in a diff. A line-ending mismatch. Check git config --get core.autocrlf and consider adding a .gitattributes file as described above.
warning: LF will be replaced by CRLF. Informational, not an error. Git is telling you it is
applying the conversion you configured.
Git Bash cannot find a program that works in PowerShell. The two shells have different PATH
handling. Use PowerShell for Windows-native tooling and Git Bash for Unix-style workflows.
A credential prompt appears on every push. GCM is not configured. Run
git config --global credential.helper manager.
Authentication fails after changing a password or rotating a token. A stale credential is cached. Remove the host’s entry from Windows Credential Manager and try again.
fatal: detected dubious ownership in repository. Git refuses to operate on a repository owned by
a different user account — a safety check against a real attack. If the ownership is legitimate (a
repository on another drive, or one created by a different account on the same machine):
git config --global --add safe.directory C:/path/to/repoAdd specific paths. Do not disable the check globally.
Long path errors on deeply nested files. Windows historically limited paths to 260 characters:
git config --global core.longpaths trueWorking in WSL
Section titled “Working in WSL”If you use Windows Subsystem for Linux, note that WSL has its own filesystem and its own Git installation. Installing Git for Windows does not install Git inside WSL, and the two keep separate configuration files.
Inside a WSL distribution, install Git with that distribution’s package manager — for Ubuntu, follow Lesson 4.
Uninstalling Git
Section titled “Uninstalling Git”Use Settings → Apps → Installed apps, find Git, and choose uninstall. Or via winget:
winget uninstall --id Git.Git -eYour global configuration in C:\Users\<you>\.gitconfig is not removed. Delete it manually for a
clean slate.
What You Learned
Section titled “What You Learned”- Git for Windows is the official distribution; install it with
winget install --id Git.Git -e --source wingetor the installer from git-scm.com. - Open a new terminal after installing so the updated
PATHtakes effect. - Git Bash, PowerShell and Command Prompt all run Git identically; Windows Terminal hosts any of them.
core.autocrlf=trueis the correct Windows default, and.gitattributesis the better team-wide fix.- Git Credential Manager stores credentials in the encrypted Windows credential store.
- Configuration resolves across system, global and local scopes, with local winning.
- WSL has its own separate Git installation and configuration.
Try It Yourself
Section titled “Try It Yourself”- Run
git --versionand note the Windows-specific version suffix. - Run
git config --list --show-scopeand identify which settings came from the system scope — those are the ones the installer chose for you. - Check
git config --get core.autocrlf. Predict what it will be before you run it. - Create a scratch folder, run
git init, and confirm the branch is namedmain.
Next Lesson
Section titled “Next Lesson”If you also use macOS, the next lesson covers it. Otherwise skip ahead and build a real repository.