DevOps
Git
Git Cheat Sheet

Git Cheat Sheet

A high-density reference guide for the essential Git commands covered in this professional curriculum.


🛠️ Setup & Config

CommandResult
git initInitialize a new local repository.
git clone <url>Download a copy of a remote repository.
git config --global user.name "Your Name"Set your global commit identity username.
git config --global user.email "you@email.com"Set your global commit identity email.

📸 Basic Snapshots

CommandResult
git add <file>Stage a file for the next commit.
git commit -m "msg"Snapshot your staged changes with a message.
git statusShow the current state of files (Modified/Staged).
git diffView unstaged changes in your files.

🌿 Branching & Merging

CommandResult
git branchList all local branches.
git switch -c <name>Create and switch to a new branch.
git merge <name>Merge the specified branch into your current one.
git rebase <base>Replay your commits on top of another base.

☁️ Collaboration (Remotes)

CommandResult
git remote add origin <url>Link your local repo to a remote server.
git push origin <branch>Upload your local commits to the server.
git pull origin <branch>Download AND merge changes from the server.
git fetch originDownload changes from the server (does NOT merge).

🔄 Undoing & Fixing

CommandResult
git reset --hard <hash>Roll back to a commit and delete all local work.
git revert <hash>Create a new commit that undoes an old one.
git cherry-pick <hash>Surgically apply one specific commit to your branch.
git stashTemporarily save uncommitted work to switch focus.

🔍 Code Forensics

CommandResult
git log --onelineView short history of commits.
git blame <file>See who modified every line in a file and when.
git show <hash>View the content changes of a specific commit.
git bisectUse binary search to find the commit that broke code.

[!TIP] Pro Tip: Use git help <command> (e.g., git help rebase) to open the local manual page for any Git tool in your browser!