Logo

Quick Reference

Git & GitHub Professional

From your first commit to reflog. Everything you need to master Git like a pro.

๐Ÿš€ Core Workflow & Setup

Setup / InitInitializes a new Git repository.
git init
Clone projectCopies an existing repository from GitHub.
git clone <url>
ConfigurationSets global username and email.
git config --global user.name "Name"
Check statusShows modified files and the current branch.
git status
Add filesStages changes for commit.
git add .
Staging area (alternative)Synonym for git add.
git stage .
Create commitSaves the current snapshot.
git commit -m "msg"
UploadSends local commits to the remote server.
git push
DownloadFetches changes from the server and merges them.
git pull
Remote infoUpdates info about remote changes without merging.
git fetch

๐ŸŒฟ Branching, Merging & Tags

Create branchCreates a new branch.
git branch <name>
Switch branchModern way to switch branches.
git switch <name>
Checkout (legacy)Older command to switch branches or files.
git checkout <name>
MergeMerges changes into the current branch.
git merge <branch>
RebaseReplays your changes on top of another branch.
git rebase <branch>
Set tagsMarks important points (releases) in history.
git tag -a v1.0
Merge toolsLaunches a visual tool for conflict resolution.
git mergetool

๐Ÿšจ Fix Errors & Recovery

Amend last commitModifies the last commit message or adds files.
git commit --amend
Reset (soft)Undoes commit, keeps changes in staging.
git reset --soft HEAD~1
Reset (hard)WARNING: Resets everything to the last commit.
git reset --hard HEAD
Restore fileUndoes changes to a file.
git restore <file>
Undo changeCreates a new commit that undoes an old one.
git revert <commit>
Delete untracked filesDeletes files not tracked by Git.
git clean -fd

๐Ÿ” History & Inspection

Show historyCompact list of all commits.
git log --oneline
Show detailsShows changes of a specific commit.
git show <commit>
Check differencesCompares changes between working directory and staging.
git diff
Find culpritShows line by line who changed what and when.
git blame <file>
Search codeEfficiently searches for text across the repository.
git grep "search"
Reflog (safety net)Log of all HEAD movements (rescues lost commits).
git reflog
StatisticsShows a summary of commits per author.
git shortlog -sn

๐Ÿง™โ€โ™‚๏ธ Advanced Expert Tools

Binary search for bugsUses binary search to find which commit introduced a bug.
git bisect
List filesShows all files currently tracked by Git.
git ls-files
CleanupOptimizes the repository and removes unnecessary objects.
git gc
Move/rename fileMoves a file and tracks the change immediately.
git mv <old> <new>
Delete fileDeletes a file from the working directory and index.
git rm <file>
Graphical interfaceLaunches the integrated graphical interface of Git.
git gui
๐Ÿ’ก

If you've really messed something up and can't find the commit anymore: git reflog is your ultimate lifesaver!