Git
How to Install Git on Windows Using Command Line (CMD)?
Git is a powerful version control system widely used in software development. Installing Git on Windows allows you to manage your code repositories efficiently. While many users prefer a graphical installer, installing Git through the command line offers a lightweight and flexible approach.
In this blog, we’ll guide you through installing Git on a Windows machine using the Command Prompt (CMD).
Step-by-Step Guide to Install Git on Windows Using CMD
1. Verify If Git is Already Installed
Before installing Git, check if it’s already installed on your system:
- Open the Command Prompt.
- Press
Win + R
, typecmd
, and press Enter.
- Run the following command:
git --version
- If Git is installed, the version number will be displayed.
- If not, you’ll receive an error message indicating the command is not recognized.
2. Download the Git Installer
You can download the latest version of Git directly using CMD. Follow these steps:
- Navigate to a Directory
Choose a directory to download the installer. Use thecd
command to navigate:
cd C:\Users\<YourUsername>\Downloads
- Download Git
Use thecurl
command to download the Git installer.
curl -o git-installer.exe https://github.com/git-for-windows/git/releases/latest/download/Git-2.42.0-64-bit.exe
(Replace the URL with the latest version’s URL if needed.)
3. Install Git Using the Silent Installer
Once the installer is downloaded, execute it silently using the command line. This method installs Git without requiring any manual input during the installation process.
Run the following command:
git-installer.exe /SILENT
- The
/SILENT
flag ensures the installation runs without any user interaction. - Git will be installed with default settings, including Git Bash, Git GUI, and essential tools.
4. Add Git to the System Path (Optional)
If Git is not automatically added to your system’s PATH during installation, you can do it manually through CMD:
- Locate the Installation Directory
The default installation path for Git is:
C:\Program Files\Git\bin
- Add to PATH
Use thesetx
command to add Git to your PATH:
setx PATH "%PATH%;C:\Program Files\Git\bin"
- Restart CMD
Close and reopen Command Prompt for the changes to take effect.
5. Verify the Installation
After installation, verify that Git is properly set up by running:
git --version
If the installation was successful, the command will output the installed version of Git.
Bonus: Configure Git After Installation
Once Git is installed, configure it to work with your repositories by setting your username and email.
- Set your username:
git config --global user.name "Your Name"
- Set your email:
git config --global user.email "[email protected]"
- Verify the configuration:
git config --list
Troubleshooting Common Issues
1. “Command not recognized” After Installation
- Ensure Git is added to your system’s PATH.
- Verify the installation directory and update the PATH variable accordingly.
2. Download Errors Using curl
- If
curl
is not available, download the installer manually from git-scm.com.
Conclusion
Installing Git on Windows using the Command Prompt is a quick and efficient method that gives you control over the process. Once installed, you can seamlessly manage your repositories, collaborate with your team, and take full advantage of Git’s powerful version control features.
By following this guide, you’ve taken the first step toward mastering Git.