Git is the most widely used version control system, and while many developers prefer using Git Bash or GUI tools, you can also run Git commands directly in the Windows Command Prompt (CMD). This is particularly useful if you’re more comfortable with CMD or working in environments where Git Bash isn’t available.
In this article, we’ll walk through how to install Git, set it up for CMD, and run basic Git commands.
✅ Prerequisites
Before running Git commands in CMD, ensure Git is installed on your system.
🔹 Step 1: Download and Install Git for Windows
- Visit the official Git website: https://git-scm.com
- Download the Windows version.
- During installation:
- Choose default editor (e.g., VS Code, Vim)
- Select “Git from the command line and also from 3rd-party software” when prompted
- Finish the setup
This ensures Git is added to your system’s PATH variable and accessible from CMD.
✅ Step 2: Verify Git in CMD
Open Command Prompt and run:
git --version
You should see output like:
git version 2.xx.x.windows.x
If not, Git may not be correctly installed or the PATH variable isn’t configured properly.
✅ Step 3: Run Git Commands in CMD
Here are common Git commands you can use in CMD:
🔹 Initialize a Git repository
git init
🔹 Clone a repository
git clone https://github.com/user/repo.git
🔹 Check repository status
git status
🔹 Stage changes
git add .
🔹 Commit changes
git commit -m "Your commit message"
🔹 Push to a remote repository
git push origin main
✅ CMD vs Git Bash
Feature | CMD | Git Bash |
---|---|---|
Native to Windows | ✅ Yes | ❌ No (requires Git install) |
Supports Git commands | ✅ Yes (if Git is installed) | ✅ Yes |
Unix-like utilities | ❌ No | ✅ Yes (e.g., ls , grep ) |
Tip: CMD lacks Unix-like commands (e.g., ls
, cat
), but is perfectly capable of running all Git operations.
🧠 Tips for Using Git in CMD
- Use double quotes (
"
) for commit messages and file paths with spaces. - Use
cd
to navigate directories before running Git commands:
cd C:\Users\YourName\Projects\my-repo
- Run
git help <command>
to get usage info for any Git command:
git help commit
✅ Summary
Task | Command Example |
---|---|
Check Git version | git --version |
Initialize repo | git init |
Clone repo | git clone <repo-url> |
Add files | git add . |
Commit changes | git commit -m "message" |
Push to remote | git push origin main |
🚀 Final Thoughts
Running Git in CMD on Windows is simple and effective once Git is correctly installed and configured. While CMD lacks some of the Unix tools offered by Git Bash, it’s fully capable of supporting your Git workflow.