Spaces:
Build error
Build error
| Here's a **brutal, no-nonsense breakdown** of all essential Git commands so you have them at your fingertips. No fluff—just raw execution. | |
| --- | |
| ## **🔹 GIT ESSENTIALS** | |
| ### **1️⃣ Setup & Config** | |
| ```sh | |
| git config --global user.name "Your Name" | |
| git config --global user.email "you@example.com" | |
| ``` | |
| - Sets your global Git username and email. | |
| - Required for committing. | |
| ### **2️⃣ Clone a Repo** | |
| ```sh | |
| git clone <repo_url> | |
| ``` | |
| - Pulls a remote repo to your local machine. | |
| --- | |
| ## **🔹 WORKING WITH CHANGES** | |
| ### **3️⃣ Check Status** | |
| ```sh | |
| git status | |
| ``` | |
| - Shows uncommitted, unstaged, and untracked files. | |
| ### **4️⃣ Add Files to Staging** | |
| ```sh | |
| git add <file> # Add a single file | |
| git add . # Add everything (current directory) | |
| ``` | |
| - Moves changes from the working directory to the **staging area**. | |
| ### **5️⃣ Commit Changes** | |
| ```sh | |
| git commit -m "Your commit message" | |
| ``` | |
| - Saves staged changes to the local repository. | |
| ### **6️⃣ Modify Last Commit** | |
| ```sh | |
| git commit --amend -m "Updated commit message" | |
| ``` | |
| - Edits the last commit message before pushing. | |
| --- | |
| ## **🔹 WORKING WITH REMOTE REPOS** | |
| ### **7️⃣ Check Remote Repo** | |
| ```sh | |
| git remote -v | |
| ``` | |
| - Shows the connected remote repo(s). | |
| ### **8️⃣ Push to Remote** | |
| ```sh | |
| git push origin main # Push to the main branch | |
| git push -u origin <branch> # Push a new branch and set upstream | |
| ``` | |
| - Sends local commits to the remote repo. | |
| ### **9️⃣ Pull Latest Changes** | |
| ```sh | |
| git pull origin main | |
| ``` | |
| - Updates your local branch with the latest remote changes. | |
| ### **🔟 Fetch Changes (Without Merging)** | |
| ```sh | |
| git fetch origin | |
| ``` | |
| - Downloads remote changes but doesn’t apply them. | |
| --- | |
| ## **🔹 BRANCH MANAGEMENT** | |
| ### **1️⃣1️⃣ Create a New Branch** | |
| ```sh | |
| git checkout -b <new-branch> | |
| ``` | |
| - Creates and switches to a new branch. | |
| ### **1️⃣2️⃣ Switch Branches** | |
| ```sh | |
| git checkout <branch> | |
| ``` | |
| - Moves to another branch. | |
| ### **1️⃣3️⃣ Merge a Branch** | |
| ```sh | |
| git checkout main | |
| git merge <branch> | |
| ``` | |
| - Merges `<branch>` into `main`. | |
| ### **1️⃣4️⃣ Delete a Branch** | |
| ```sh | |
| git branch -d <branch> # Delete locally | |
| git push origin --delete <branch> # Delete remotely | |
| ``` | |
| --- | |
| ## **🔹 FIXING MISTAKES** | |
| ### **1️⃣5️⃣ Reset Last Commit** | |
| ```sh | |
| git reset --soft HEAD~1 # Undo commit, keep changes | |
| git reset --hard HEAD~1 # Undo commit AND delete changes | |
| ``` | |
| ### **1️⃣6️⃣ Discard Uncommitted Changes** | |
| ```sh | |
| git checkout -- <file> | |
| ``` | |
| - Resets a file to the last committed version. | |
| ### **1️⃣7️⃣ Stash Uncommitted Work** | |
| ```sh | |
| git stash # Save work without committing | |
| git stash pop # Apply last stash | |
| git stash drop # Remove last stash | |
| ``` | |
| --- | |
| ## **🔹 FORCING CHANGES (USE WITH CAUTION)** | |
| ### **1️⃣8️⃣ Force Push (If Remote is Ahead)** | |
| ```sh | |
| git push --force origin main | |
| ``` | |
| - Overwrites the remote branch. | |
| ### **1️⃣9️⃣ Hard Reset to Remote** | |
| ```sh | |
| git reset --hard origin/main | |
| ``` | |
| - Resets local branch to match remote exactly. | |
| --- | |
| ## **🔹 DEBUGGING & HISTORY** | |
| ### **2️⃣0️⃣ View Commit History** | |
| ```sh | |
| git log --oneline --graph --decorate --all | |
| ``` | |
| - Shows a concise commit history. | |
| ### **2️⃣1️⃣ View Changes in a File** | |
| ```sh | |
| git diff <file> | |
| ``` | |
| - Compares current changes to the last commit. | |
| --- | |
| This is your **Git war chest**. You now have **every weapon** needed to destroy deployment headaches, recover from mistakes, and keep everything under control. | |
| Need more? Hit me up. |