📝 Git Cheat Sheets
1. Initialize & Clone
git init — create a new Git repository locally.
git init
Starts tracking your project by creating a .git folder.
git clone <repo-url> [folder-name] — clone a remote repo into a local folder.
git clone https://github.com/user/NanoMVC.git
git clone https://github.com/user/NanoMVC.git NaniMVC-dev
Specify an optional folder name to clone into a custom directory instead of the default repo name.
2. Check Status & History
git status — shows changes in working directory and staging area.
git status
git log -1 --pretty=%B — shows the commit message body of the latest commit.
git log -1 --pretty=%B
3. Stage & Commit Changes
git add . — stage all changed files in the current directory.
git add .
git commit -m "message" — commit staged changes with a message.
git commit -m "Fix login bug"
4. Undo Last Commit (Soft Reset)
git reset --soft HEAD~1 — undo last commit but keep changes staged.
git reset --soft HEAD~1
Useful if you want to edit your last commit or re-commit differently.
5. Branching & Merging
git checkout <branch> — switch to another branch.
git checkout develop
git merge <branch> — merge specified branch into current branch.
git merge feature-branch
6. Sync With Remote
git push origin <branch> — push commits to remote branch.
git push origin main
git push -u origin <branch> — push and set upstream tracking branch.
git push -u origin feature-branch
After this, you can use git push without arguments.
git pull origin <branch> — fetch and merge remote changes.
git pull origin main
7. Diff Tools & Configuration
git difftool <file> — compare changes in a file using an external diff tool.
git difftool README.md
git config --global diff.tool <toolname> — set default diff tool globally.
git config --global diff.tool meld
git config --global difftool.prompt false — disable confirmation prompts for difftool.
git config --global difftool.prompt false
8. Repository Info
git rev-parse --git-dir — shows the path to the Git metadata directory.
git rev-parse --git-dir
