Skip to content
๐Ÿงญ Git Commands

๐Ÿงญ Git Commands

Git is a version controls system, and here are the commands that you ought to know to navigate this control system effectively


๐Ÿ”ฐ 1. Initialization & Setup

CommandPurpose
git initCreate a new Git repo locally
git clone <url>Clone a remote repo
git remote -vView remote URLs (origin, upstream)
git remote add origin <url>Link local repo to GitHub
git remote remove upstreamRemove noisy upstream tracking

๐Ÿ“ฆ 2. Staging & Committing

CommandPurpose
git statusSee current changes and branch state
git add <file>Stage a file for commit
git add .Stage all changes
git commit -m "message"Commit staged changes with a message
git logView commit history

๐Ÿš€ 3. Pushing & Pulling

CommandPurpose
git push origin mainPush local commits to GitHub
git pull origin mainPull latest changes from GitHub
git fetchUpdate remote tracking info without merging
git merge origin/mainMerge fetched changes into local branch

๐ŸŒฟ 4. Branching

CommandPurpose
git branchList local branches
git branch <name>Create a new branch
git checkout <name>Switch to a branch
git switch -c <name>Create and switch to a branch (modern)
git push origin <branch>Push new branch to GitHub
git branch -d <name>Delete local branch
git branch --set-upstream-to=origin/mainRebind tracking to your own repo

๐Ÿงน 5. Undo & Cleanup

CommandPurpose
git restore <file>Undo changes to a file
git reset HEAD <file>Unstage a file
git reset --hardReset everything to last commit (โš ๏ธ destructive)
git clean -fdRemove untracked files and folders (โš ๏ธ destructive)

๐Ÿงช 6. Validator Audit & Diff

CommandPurpose
git diffSee unstaged changes
git diff --cachedSee staged changes
git show <commit>Inspect a specific commit
git blame <file>See who changed each line
Last updated on