Basic Git Commands for Windows Users |
Git is a powerful version control system that is widely used for tracking
changes in software development projects. To use Git on Windows, you
can either install Git for Windows, which provides a Git command-line
interface and a graphical user interface (Git GUI), or you can use Git
through a Windows Subsystem for Linux (WSL) if you have WSL installed.
Here are some basic Git commands you can use on Git for Windows:
1. Initialize a new Git repository:
git init
2. Clone a remote repository:
git clone [repository_url]
3. Add changes to the staging area:
git add [file(s)]
4. Commit changes with a message:
git commit -m "Your commit message here"
5. Check the status of your working directory:
git status
6. Fetch and merge changes from a remote repository:
git pull
7. Push your changes to a remote repository:
git push
8. List all branches:
git branch
9. Switch to a different branch:
git checkout [branch_name]
10. Merge changes from another branch:
git merge [branch_name]
11. Display commit history:
git log
12. List remote repositories:
git remote -v
13. Fetch changes from a specific remote repository:
git fetch [remote_name]
14. Add a new remote repository:
git remote add [remote_name] [remote_url]
15. Show the differences between your working directory and the last commit:
git diff
16. Unstage changes from the staging area:
git reset [file(s)]
17. Remove files from Git and the working directory:
git rm [file(s)]
18. Rename a file in Git:
git mv [old_file] [new_file]
- You can run these commands individually in your command prompt or Git Bash as needed for your Git workflow. Make sure to replace `[repository_url]`, `[file(s)]`, `[branch_name]`, `[remote_name]`, `[remote_url]`, and `"Your commit message here"` with the appropriate values for your specific use case.
- These are some of the most commonly used Git commands. Git has many more features and options, so it's worth exploring the Git documentation or using the `git --help` command to learn more about specific commands or options.
- If you're using Git through WSL, you can use the same Git commands as you would in a regular Linux environment. Just open a terminal within your WSL instance and run the Git commands mentioned above.