Git Commands Cheat Sheet
Here’s a quick reference for commonly used Git commands:
- Initialize a Repository
git init
- Clone a Repository
git clone <repository_URL>
- Add Changes to Staging Area
git add <file_name>
git add . - Commit Changes
git commit -m "Commit message"
- Push Changes to Remote Repository
git push origin <branch_name>
- Pull Changes from Remote Repository
git pull origin <branch_name>
- Check Status
git status
- Check Differences
git diff
- Create a New Branch
git branch <branch_name>
- Switch to a Branch
git checkout <branch_name>
- Merge Branches
git merge <branch_name>
- View Commit History
git log
- Undo Changes in Working Directory
git checkout -- <file_name>
- Undo Changes in Staging Area
git reset HEAD <file_name>
- Undo Last Commit
git reset HEAD^
- Revert to a Previous Commit
git reset --hard <commit_SHA>
- Create a Tag
git tag <tag_name>
- List Tags
git tag
- Delete a Tag
git tag -d <tag_name>
- Fetch Remote Changes
git fetch
These are some commonly used Git commands. Make sure to replace placeholders like <branch_name> and <file_name> with actual branch names or file names.