quantumFreedom / git-war-chest.md
ccncio's picture
added ap.py
3bc16cc
|
Raw
History Blame Contribute Delete
3.49 kB

A newer version of the Gradio SDK is available: 6.22.0

Upgrade

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

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

git clone <repo_url>
  • Pulls a remote repo to your local machine.

🔹 WORKING WITH CHANGES

3️⃣ Check Status

git status
  • Shows uncommitted, unstaged, and untracked files.

4️⃣ Add Files to Staging

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

git commit -m "Your commit message"
  • Saves staged changes to the local repository.

6️⃣ Modify Last Commit

git commit --amend -m "Updated commit message"
  • Edits the last commit message before pushing.

🔹 WORKING WITH REMOTE REPOS

7️⃣ Check Remote Repo

git remote -v
  • Shows the connected remote repo(s).

8️⃣ Push to Remote

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

git pull origin main
  • Updates your local branch with the latest remote changes.

🔟 Fetch Changes (Without Merging)

git fetch origin
  • Downloads remote changes but doesn’t apply them.

🔹 BRANCH MANAGEMENT

1️⃣1️⃣ Create a New Branch

git checkout -b <new-branch>
  • Creates and switches to a new branch.

1️⃣2️⃣ Switch Branches

git checkout <branch>
  • Moves to another branch.

1️⃣3️⃣ Merge a Branch

git checkout main
git merge <branch>
  • Merges <branch> into main.

1️⃣4️⃣ Delete a Branch

git branch -d <branch>  # Delete locally
git push origin --delete <branch>  # Delete remotely

🔹 FIXING MISTAKES

1️⃣5️⃣ Reset Last Commit

git reset --soft HEAD~1  # Undo commit, keep changes
git reset --hard HEAD~1  # Undo commit AND delete changes

1️⃣6️⃣ Discard Uncommitted Changes

git checkout -- <file>
  • Resets a file to the last committed version.

1️⃣7️⃣ Stash Uncommitted Work

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)

git push --force origin main
  • Overwrites the remote branch.

1️⃣9️⃣ Hard Reset to Remote

git reset --hard origin/main
  • Resets local branch to match remote exactly.

🔹 DEBUGGING & HISTORY

2️⃣0️⃣ View Commit History

git log --oneline --graph --decorate --all
  • Shows a concise commit history.

2️⃣1️⃣ View Changes in a File

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.