✅ Git Cheat Sheet — Step-by-Step Guide for GitHub
📂 Phase 1: Pushing a File to GitHub (First Time)
1️⃣ Initialize Git in Your Project Folder
Sets up a new Git repository.
2️⃣ Link to Your GitHub Repository
Connects your local repo to GitHub.
3️⃣ Stage Files for Commit
or to add all files:
4️⃣ Commit the Files
Saves changes in Git history.
5️⃣ Push Files to GitHub
Replace main with your branch name, e.g., master if needed.
📝 Phase 2: Modify & Push Updates
1️⃣ Edit demo.txt
2️⃣ Check Status
3️⃣ Stage Updated File
4️⃣ Commit the Changes
5️⃣ Push Changes to GitHub
🎯 Bonus Git Commands
🔹 Check Commit History
🔹 Clone an Existing Repository
🔹 List Files in Folder
🛠️ Configure Git (One Time Setup)
🔄 Restore a File from a Previous Commit
1️⃣ Check Commit History
2️⃣ Restore a Specific File
Restores demo.txt from specific commit.
3️⃣ View File from Old Commit Without Changing Anything
🌿 Git Branching: Create, Switch, Merge
| Action | Command |
|---|---|
| Create a branch | git branch feature-branch |
| Switch to a branch | git checkout feature-branch or git switch feature-branch |
| Create & Switch | git checkout -b feature-branch or git switch -c feature-branch |
| List branches | git branch |
| Merge branch to main | git merge feature-branch |
| Delete a branch | git branch -d feature-branch |
| Force delete a branch | git branch -D feature-branch |
| Push branch to GitHub | git push origin feature-branch |
| Delete branch from GitHub | git push origin --delete feature-branch |
📝 Example Workflow of Branching
1️⃣ Create & Switch to Branch
2️⃣ Make Changes, Add & Commit
3️⃣ Switch Back & Merge
4️⃣ Delete Branch
No comments:
Post a Comment