Skip to content

Latest commit

 

History

History
222 lines (149 loc) · 2.24 KB

File metadata and controls

222 lines (149 loc) · 2.24 KB

🚀 Complete GitHub Commands Guide

🧱 1. Initial Setup (First Time Only)

git config --global user.name "Your Name"
git config --global user.email "your@email.com"
git config --list

📁 2. Create / Initialize Repository

Start a new repo

git init

Clone existing repo

git clone https://github.com/username/repo.git

📦 3. Basic Workflow

git status
git add .
git commit -m "your message"

🌐 4. Connect to GitHub

git remote add origin https://github.com/username/repo.git
git remote -v

🚀 5. Push Code

First push

git branch -M main
git push -u origin main

Next pushes

git push

⬇️ 6. Pull Latest Code

git pull origin main

Recommended

git pull origin main --rebase

🔄 7. Daily Workflow (Best Practice)

git pull origin main --rebase
git add .
git commit -m "update"
git push

🌿 8. Branching

git branch feature-branch
git checkout feature-branch

Create + switch

git checkout -b feature-branch

Modern way

git switch feature-branch

🔀 9. Merge Branch

git checkout main
git merge feature-branch

❌ 10. Undo Changes

Unstage file

git reset file.py

Undo last commit (keep changes)

git reset --soft HEAD~1

Undo last commit (delete changes)

git reset --hard HEAD~1

⚠️ 11. Force Push

git push origin main --force

🔍 12. View Logs

git log
git log --oneline

📂 13. Remove Files

git rm file.py
git commit -m "removed file"

🧹 14. .gitignore Example

.env
venv/
__pycache__/
node_modules/
models/

🔗 15. Fix Common Errors

Rejected push

git pull origin main --rebase
git push

Change remote URL

git remote remove origin
git remote add origin NEW_URL

🧠 16. Advanced Commands

Stash changes

git stash
git stash pop

Check differences

git diff

🎯 Quick Cheat Sheet

git pull origin main --rebase
git add .
git commit -m "update"
git push