Skip to main content

📘 Essential Git Commands

A quick reference guide for everyday Git usage.


🛠️ Repository Setup​

  • git init — Create a new Git repository
  • git clone <url> — Copy a remote repository to your machine
  • git config — Set global name/email for Git

📦 Staging & Committing​

  • git status — Show modified/untracked files
  • git add . — Stage all file changes
  • git commit -m "msg" — Save staged changes with a message

🌿 Branching​

  • git branch — List or create branches
  • git checkout <branch> — Switch to a branch
  • git merge <branch> — Merge another branch into current one

🌐 Working with Remotes​

  • git remote add origin <url> — Connect to a remote repo
  • git push -u origin main — Push commits to remote
  • git pull — Fetch + merge changes from the remote repo

♻️ Undoing Changes​

  • git reset — Unstage a file
  • git revert <commit> — Undo a commit with a new one
  • git stash — Temporarily save changes

🧠 Additional Useful Commands​

  • git log --oneline — Compact history view
  • git stash pop — Restore stashed changes
  • git switch -c new-feature — Create and switch to a new branch
  • git rebase — Clean and reapply commits (advanced)

✅ Use this as a reference when working with Git in your local or collaborative projects!