
Help in Git
🚀 Git Help & Common Commands Guide
Git is a powerful version control system, and sometimes you may need help with commands or troubleshooting issues. Here’s how you can get help in Git and some commonly used commands.
📌 Getting Help in Git
Git provides built-in help commands:
1️⃣ Check available commands:
git help
2️⃣ Get help for a specific command:
git help <command>
Example:
git help commit
3️⃣ Shortcut for help pages:
git <command> --help
Example:
git status --help
4️⃣ View help in the terminal itself (without opening manual pages):
git <command> -h
Example:
git log -h
🔥 Common Git Commands
1️⃣ Check Git Version
git --version
2️⃣ Configure Git (Set Username & Email)
git config --global user.name "Your Name"git config --global user.email "your-email@example.com"
3️⃣ Initialize a New Repository
git init
4️⃣ Clone an Existing Repository
git clone https://github.com/username/repository.git
5️⃣ Check the Status of Your Repo
git status
6️⃣ Add Changes to Staging
git add .
7️⃣ Commit Changes
git commit -m "Your commit message"
8️⃣ Push Changes to GitHub
git push origin main
9️⃣ Pull Latest Changes from Remote
git pull origin main
🔟 Create and Switch to a New Branch
git checkout -b feature-branch
1️⃣1️⃣ List All Branches
git branch
1️⃣2️⃣ Merge a Branch
git checkout maingit merge feature-branch
1️⃣3️⃣ Reset Changes
Undo uncommitted changes:
git checkout -- filename
Reset to the last commit:
git reset --hard
1️⃣4️⃣ View Commit History
git log --oneline --graph --decorate --all
💡 Troubleshooting Git Issues
1️⃣ Fix "fatal: Not a git repository"
Run this inside a Git project folder:
git init
2️⃣ Fix "detached HEAD" Issue
git checkout main
3️⃣ Fix Merge Conflicts
- Open conflicting files.
- Manually resolve conflicts (
<<<<<<<
,=======
,>>>>>>>
). - Add and commit changes:
git add .git commit -m "Resolved merge conflict"
🎯 Summary
- Use
git help <command>
to get help. - Use
git status
to check your repo. - Commit and push changes with
git add .
,git commit -m "msg"
,git push origin main
. - Create branches with
git checkout -b branch-name
. - Fix merge conflicts manually and commit.