How to Install and Use Git on Windows

Git is a version control tool that tracks changes in your code and supports collaboration through local and remote repositories. When you install Git on Windows, you get access to Git Bash, Git GUI, and seamless integration with editors like VS Code.

This guide shows you how to install Git on Windows, configure Git for the first time, use Git Bash, manage repositories, and troubleshoot common Git issues.

Prerequisite

Before you begin, you need to:

  • Have access to a Windows system with administrator privileges.
  • Understand basic Git terms like commit, branch, and clone.

Download Git for Windows

Install Git on Windows

You can download Git from the official website or install it using a package manager like Chocolatey or Winget.

Download Git for Windows from the Official Website

Use the official website to download the git installer manually on your Windows system.

  • Go to the Git Official Website download page and choose the appropriate installer for your system architecture (32-bit or 64-bit).
  • Launch the downloaded .exe file. When prompted with the license agreement screen, click Install to continue.
  • The installer extracts and installs the required files. You’ll see a progress bar during this process.
  • Once installation is complete, ensure the options Launch Git Bash and View Release Notes are selected, then click Finish.
  • Open Git Bash and run the following command to confirm git was installed correctly:
git --version

Download Git for Windows using Chocolatey

Chocolatey is a Windows package manager that lets you install software like git using simple commands in PowerShell or Command Prompt.

Using Command Prompt

  1. Open Command Prompt as Administrator.
    • Press Win + X and select Command Prompt (Admin).
  2. Run the following command:
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Using PowerShell

  • Open PowerShell as Administrator.
    • Press Win + X and select Windows PowerShell (Admin).
  • Run the following command:
Set-ExecutionPolicy Bypass -Scope Process -Force; ` [System.Net.ServicePointManager]::SecurityProtocol = ` [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; ` iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
  • Verify installation. choco --version The command returns a version number, such as 2.5.0
  • To install Git with Chocolatey, open PowerShell as Administrator and run:
choco install git

Download Git for Windows using Winget

Winget is a command-line tool built into Windows for quick software installation and updates.

  • Check if winget is available.

Open PowerShell or Command Prompt, and run:

winget --version

If the terminal returns an error like:

'winget' is not recognized as an internal or external command, operable program or batch file.

Install App Installer from the Microsoft Store:

winget --version

Output:

1.9.25200

Use Winget to Install Git on Windows:

  • After winget is installed, run the following command to install Git:
winget install --id Git.Git -e --source winget

Initial Configuration of Git

After installing Git on Windows, configure your identity so your commits can be properly tracked. Use the git config command to set global options for your name and email address.

  • Configure Git Username and Email
<code>git config --global user.name "Your Name" git config --global user.email "Your Email"

Command breakdown:

  • git config: The command to set Git configuration.
  • --global: Applies the setting for all repositories on your system.
  • user.name: Key that sets your Git display name.
  • user.email: Key that sets the email address used in commits.
  • “Your Name”: Replace this with the name you want to associate with your commits.
  • “Your Email”: Replace with your email address.

Example:

<code>git config --global user.name "EEEBuntu Admin" git config --global user.email "[email protected]"
  • Configuring the Default Branch Name

Git versions before 2.28 defaulted to master the initial branch name. Modern versions may default to main or allow configuration.

git config --global init.defaultBranch main

View configurations

git config --list

Output:

user.name=<span style="background-color: initial; font-family: inherit; font-size: inherit; text-align: initial; color: inherit; letter-spacing: 0em;">EEEBuntu Admin</span>
[email protected] 
init.defaultbranch=main

Using Git Bash on Windows

Git Bash is a command-line tool for Windows that provides a Unix-like shell environment. It supports standard Linux commands such as ls, cat, <a href="https://eeebuntu.org/linux-commands/touch">touch</a>, and rm, making it familiar for Linux users. Git Bash is commonly used for executing git commands, writing shell scripts, and managing SSH keys. Below are some basic Git Bash examples on Windows:

  • Example 1: Using Git Bash to Create and View a File
touch my-project-file.txt
echo "Welcome to EEEBuntu" > my-project-file.txt
cat my-project-file.txt
  • Example 2: Check Current Directory pwd

Output:

/c/Users/Administrator

Using Git Bash to Create and Initialize Repositories

Start version control by creating a new project directory or using an existing one. Initialize it with Git to begin tracking changes and managing the project’s history.

  • Create New Repository
mkdir my-project

The above command creates a new repo called my-project in the current location.

  • Navigate to the newly created directory
   cd my-project

This changes your current working directory to the my-project.

  • Initialize Repository
git init

The git init command initializes a new Git repository in your current directory. It creates a hidden .git folder that stores all Git-related configuration and history.

Git Workflow

Git uses a distributed workflow that lets you make changes, stage them, and commit them to your local repository before pushing them to a remote.

Understand the Three Key Areas:

  • Working Directory: Modify files in your project. Git detects changes.
  • Staging Area (Index): Add selected changes using git add. This area holds changes you intend to commit.
  • Local Repository: Store committed snapshots using git commit. These snapshots stay in your .git directory until pushed.

Understand Git Workflow

The Git workflow follows a clear sequence of steps that lets you manage changes from development to version control effectively.

  • Create or edit files in the working directory

Start by creating or modifying files in your project folder. Git detects these changes automatically.

echo "Welcome to EEEbuntu" > my-project-file.txt
  • Check the status of changes

Use git status to see which files are modified or untracked.

git status
  • Stage changes for commit

Add specific files to the staging area using git add. This prepares the changes for commit.

git add my-project-file.txtt
  • Commit changes to the local repository

Use git commit to save a snapshot of your staged changes in the repository.

git commit -m "New Changes Applied"
  • View commit history

Check the history of commits using git log.

git log

Output:

commit b45153200596a08dc01e2b085061e4b4521286ee (HEAD -> main)
Author: EEEBuntu Admin <[email protected]>
Date:   Fri Jul 25 21:13:37 2025 +0000

Branching and Merging in Windows Git Bash

Use branching and merging in Git to manage different lines of development efficiently. Branching lets you work on features or fixes in isolation, while merging integrates those changes into a stable branch like main.

  • View existing branches
git branch

Output:

<code>*main

The asterisk (*) indicates the branch you’re currently on.

  • Create and switch a new Branch

Create a new branch and immediately switch to it using git switch -c command:

git switch -c feature

Output:

<code>Switched to a new branch 'feature`

Note: The git switch command was introduced in Git 2.23 to simplify branch switching. If you’re using an older Git version, use git checkout instead.

  • Edit Files in the New Branch

You can now make changes to your files. For example, create a new file and add some content:

   touch my-project-update.txt
   echo "This is a new feature update." > my-project-update.txt
  • Make Changes and Commit

Make necessary changes in the new branch, then stage and commit them:

touch my-project-update.txt
echo "This is a new feature update." > my-project-update.txt
  • Switch Back to Main Branch

To return to the main branch:

git switch main
  • Merge the new branch feature into main

Once your changes are tested and ready, merge the feature branch into main:

git merge feature-branch

Output:

Updating b451532..ad12dae
Fast-forward
my-project-update.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 my-project-update.txt

Working with Remote Repositories

Git lets you connect your local repository to remote repositories hosted on platforms like GitHub, GitLab, or Bitbucket. This enables collaboration, backup, and code sharing. Remote repositories store project versions on a server. You can push your local commits to the remote repository or pull changes made by others.

  • Add a Remote Repository

Use the git remote add command to link your local repo with a remote.

git remote add origin https://github.com/your-username/your-repo.git

Replace the URL with your repository’s actual remote URL.

  • Verify the Remote

Check the remote URL configuration using:

git remote -v
  • Push Changes to Remote

Push your committed changes from the local repository to the remote main branch:

git push -u origin main

The -u flag sets origin/main as the upstream for the local main branch.

When you run the above command, Git will prompt you to sign in to GitHub using your browser. Click “Sign in with your browser”, log in to GitHub, and authorize access to complete the push.

  • Pull Updates from Remote

To fetch and merge changes from the remote:

git pull

This keeps your local repository up to date with changes made by collaborators.

  • Clone a Remote Repository

To create a local copy of a remote repository:

git clone https://github.com/your-username/your-repo.git

This sets up everything you need, including the .git folder and remote tracking.

GUI Alternatives for Git on Windows

While the Git command line is powerful, many developers prefer a graphical interface (GUI) for ease of use, especially when starting. GUI tools for Git offer visual workflows, drag-and-drop staging, diff viewers, and intuitive commit histories. These tools help you perform common Git tasks, like commit, push, pull, merge, and resolve conflicts, without remembering complex commands.

GitHub Desktop: GitHub Desktop is a free, open-source Git client with a clean interface, perfect for beginners. It simplifies pushing, pulling, and managing repositories integrated directly with GitHub.

SourceTree: SourceTree offers a detailed visual interface for Git operations. It’s great for handling large projects, viewing branching, and executing Git commands without using the terminal.

GitKraken: GitKraken provides a modern, intuitive GUI with drag-and-drop Git operations. It supports advanced features like multiple diff views and GitHub, GitLab, and Bitbucket integration.

Troubleshooting Common Issues

Users may encounter setup or usage problems that disrupt workflow in Git. Below are some frequent issues along with their solutions.

Git Not Recognized in CMD

If you run git in the command prompt, and get an error like 'git' is not recognized as an internal or external command, it means Git isn’t added to your system’s PATH.

Steps to fix:

  • Reinstall Git and select the option “Add Git to system PATH” during installation.
  • Or manually add the Git bin folder to the system environment variables.

Authentication Errors with GitHub

Errors fatal: Authentication failed may appear when pushing or pulling.

Steps to fix:

  • Run gh auth login command to log in with GitHub CLI.
  • If using HTTPS, use GitHub CLI or a personal access token.

Advanced Git Features on Windows

Git offers powerful tools beyond basic version control. Mastering these advanced features enhances collaboration, conflict resolution, and workflow efficiency. Below are key Git features with examples:

Git Stash

Use git stash to temporarily save uncommitted changes in your working directory so you can switch branches or resolve urgent issues without losing your progress.

  • Stash changes:
<code>git stash

This saves your local changes and reverts the working directory to the last commit.

  • View stashed items:
<code>git stash list

Shows all your saved stashes.

  • Apply the most recent stash:
   git stash apply
  • Apply and remove from stash list:
git stash pop

Git Rebase

Use git rebase to move or combine a sequence of commits onto a new base, such as the updated main branch. This keeps your project history clean and linear, especially when updating your feature branch without introducing unnecessary merge commits.

  • First, switch to your feature branch:
git switch feature
  • Then rebase onto main:
git rebase main

If conflicts occur, Git will pause and let you resolve them.

  • After fixing conflicts:
git add . 
git rebase --continue

This rewrites your branch history as if it were built on top of the latest main.

Git Cherry-pick

Use git cherry-pick to apply a specific commit from another branch to your current branch.

  • View the commit history to find the commit you want to copy:
git log
  • Copy the desired commit hash and run:
git cherry-pick <commit-hash> 

Note: A commit hash is a unique ID for each git commit. You can find it using git log, and usually, the first 7–10 characters are enough.

Uninstalling or Updating Git

Remove git from your system or upgrade to the latest version to access new features, improvements, and security fixes.

Uninstall git on Windows using Control Panel:

Removes Git and all its components from your system. Use this when switching versions or performing a clean reinstall

  • Press Windows + S, search for Control Panel, and open it.
  • Go to Programs > Programs and Features.
  • Select Git, right-click, and choose Uninstall.
  • Follow the on-screen instructions.

Command line (if installed via Chocolatey):

choco uninstall git

To update git using the command line on Windows:

choco upgrade git

Update Git on Windows with the Official Installer:

Replaces the current Git version with the latest release.

  • Visit git-scm.com
  • Download and run the latest Git installer.
  • Follow the installation steps.

Conclusion

You installed Git on Windows, configured it, and used Git Bash to manage repositories with both basic and advanced commands. You also resolved common issues, explored GUI alternatives, and learned how to update or remove Git when needed. To learn more, visit the official Git documentation.


Photo of author
Authored by Roshan Ray
Roshan is a tech blogger and writer with over 6 years of experience in creating in-depth technical articles, documentation, and SEO-focused content. Passionate about making complex topics easy to understand, he blends technical expertise with content strategies that drive visibility and engagement.

Hide Ads for Premium Members by Subscribing
Hide Ads for Premium Members. Hide Ads for Premium Members by clicking on subscribe button.
Subscribe Now