How to Install Git on Windows Using PowerShell?

Recently, I was trying to set up Git on my new Windows laptop, which I did using PowerShell. In this tutorial, I will explain how to install Git on Windows using PowerShell. Git is a powerful version control system that allows developers to track changes in their codebase and collaborate with others efficiently. You will know how to install Git and start using it easily in your projects.

Install Git on Windows Using PowerShell

Note: You need administrative access to the computer to install Git.

Step 1: Download Git for Windows

The first step is to download the latest version of Git for Windows. Visit the official Git website and click on the download link for the 64-bit or 32-bit version, depending on your system architecture. Once the file is downloaded, proceed to the next step.

Install Git on Windows Using PowerShell

Step 2: Install Git Using the Executable

Locate the downloaded Git installer executable (e.g., Git-2.34.1-64-bit.exe) and double-click on it to start the installation process. You will be greeted with the Git Setup wizard.

Click “Next” to proceed through the installation steps. You can leave the default options selected unless you have specific requirements. When prompted to choose the default editor for Git, select your preferred text editor (e.g., Notepad++, Visual Studio Code) from the dropdown menu.

On the “Adjusting your PATH environment” screen, choose “Git from the command line and also from 3rd-party software.” This option ensures that Git is available from both PowerShell and the command prompt.

powershell install git

Continue clicking “Next” until you reach the “Configuring the line ending conversions” screen. Here, select “Checkout Windows-style, commit Unix-style line endings.” This setting helps maintain consistency across different operating systems.

powershell install git in windows

Finally, click “Install” to begin the installation process.

install git in windows using powershell

Once the installation is complete, you can launch Git Bash or proceed to the next step to configure Git in PowerShell.

configure git in powershell

Check out Disable Windows Defender Using PowerShell

Step 3: Configure Git in PowerShell

Now that Git is installed, let’s configure it in PowerShell. Open PowerShell by searching for it in the Start menu and clicking on “Windows PowerShell.”

First, check if Git is properly installed by running the following command:

git --version

If Git is installed correctly, it will display the version number, like “git version 2.47.1.windows.2”.

You can see in the screenshot below:

git version using powershell

Next, configure your user name and email address using the following commands, replacing “John Doe” and “johndoe@example.com” with your own information:

git config --global user.name "John Doe"
git config --global user.email "johndoe@example.com"

These details will be associated with your commits, making it easier to identify who made specific changes in the codebase.

Read Monitor and Manage CPU Usage using Windows PowerShell

Step 4: Enhance PowerShell with posh-git (Optional)

To further improve your Git experience in PowerShell, you can install the posh-git module. Posh-git provides helpful Git status information directly in your PowerShell prompt.

To install posh-git, run the following command in PowerShell:

Install-Module posh-git -Scope CurrentUser -Force

Once installed, you need to import the module every time PowerShell starts. To automate this process, execute the following command:

Add-PoshGitToProfile

This command adds the import statement to your PowerShell profile script, ensuring posh-git is loaded automatically whenever you open PowerShell.

Read Install Snipping Tool in Windows 11 Using PowerShell

Using Git in PowerShell

With Git installed and configured, you’re ready to start using it in your projects. Here are a few basic commands to get you started:

  1. Clone a repository:
git clone https://github.com/username/repository.git
  1. Navigate to the cloned repository:
cd repository
  1. Check the status of your repository:
git status
  1. Stage changes for commit:
git add .
  1. Commit the staged changes with a message:
git commit -m "Add new feature"
  1. Push the changes to the remote repository:
git push origin main

These are just a few examples of the many Git commands available. As you become more familiar with Git, you’ll discover additional commands that suit your development process.

Conclusion

In this tutorial, we learned how to install Git on Windows using PowerShell. We walked through the process of downloading and installing Git, configuring it in PowerShell, and optionally enhancing the experience with posh-git. With Git set up, you can now efficiently manage your codebase, collaborate with others, and take advantage of version control in your projects.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.