How to Install Git on Windows 11 & 10
In this tutorial, we'll learn how to install and configure Git on Windows. You can use this guide to set up Git on any Windows version, including Windows 11.
Installing Git
To install Git, first download the setup by going to git-scm.com/downloads/win and downloading the 64-bit Windows installer.
Once the download is complete, run the setup to start the installation. We'll mostly stick with the default options, except for a few settings.
In the window that selects components, make sure to check the options for Windows Explorer integration. This adds the 'Open Git Bash here' option to the right-click menu, which is a convenient way to quickly open a project folder in the Git Bash shell.
When choosing the default editor, it’s recommended to pick Visual Studio Code. However, you need to have it installed on your computer. If not, you have two options: cancel the setup, install VS Code, and run the setup again, or continue with the vi editor and change the default editor after installation.
For the rest of the installation, continue with the default options.
Once the installation is complete, open either PowerShell or the Git Bash terminal, and run the following command to check the Git version installed on your Windows computer:
git --version
Configuring Git (username, email, default branch)
We've successfully installed Git, but we need to do some configuration before committing to any repository.
What we need to do is set the username and email. We'll also change the name of the default branch. By default, it's called master
, but we'll change it to main
.
You can check your current global configuration with the following command:
git config --global --list
Run the following command to set the username:
git config --global user.name "your_username"
To set the email, run the following command:
git config --global user.email your_email
Run the following command to change the default branch name to main
:
git config --global init.defaultbranch main
Initializing a Git repository
Now that the configuration is set, you can start initializing Git repositories. Open a terminal, navigate to the folder you want to turn into a Git project, and run the git init
command:
git init
This command will turn your project folder into a Git repository. All Git-related data will be stored in a hidden .git
folder within your project directory.
This is a hidden folder. In Windows Explorer, you'll need to enable 'Show Hidden Items' to see the .git folder.
To view the status of your Git repository run the git status
command:
git status
To create a commit, first add your files to the staging area using the git add
command. Then, run the git commit
command to record your changes in the version history:
git add .
git commit -m "Initial Commit"
Setting Up PowerShell to Work with Git
If you prefer using PowerShell instead of Git Bash terminal, you might want to add some configuration to your PowerShell profile. This is because, unlike Git Bash, PowerShell doesn’t display the branch you're working on by default.
For a complete guide on configuring PowerShell for Git, click the link below:
Using Git command Help
To see the basic syntax and commonly used git
commands, run the git
command without any options:
git
If you want help with a specific command, like if I want to see all the options for the git log
command, I can type git log -h
.
git log -h
However, this might not show all the options. To see everything for the git log command, I can type git log --help
.
git log --help
In Windows, this will open the full man page in your default web browser.