







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This cheat sheet covers all of the Git commands I've covered in my Ultimate Git ... git commit -m “Message” # Commits with a one-line message git commit.
Typology: Slides
1 / 13
This page cannot be seen from the preview
Don't miss anything!








This cheat sheet covers all of the Git commands I’ve covered in my Ultimate Git Mastery course. ✓ (^) Creating snapshots ✓ (^) Browsing history ✓ Branching & merging ✓ Collaboration using Git & GitHub ✓ (^) Rewriting history
Want to master Git? Stop wasting your time memorizing Git commands or browsing disconnected tutorials. If you don’t know how Git works, you won’t get far. My Ultimate Git Mastery course teaches you everything you need to know to use Git like a pro. ✓ (^) Learn & understand Git inside out ✓ (^) Master the command line ✓ (^) Version your code and confidently recover from mistakes ✓ (^) Collaborate effectively with others using Git and GitHub ✓ (^) Boost your career opportunities Click below to enroll today: https://codewithmosh.com/p/the-ultimate-git-course/
Viewing the staged/unstaged changes git diff # Shows unstaged changes git diff --staged # Shows staged changes git diff --cached # Same as the above Viewing the history git log # Full history git log --oneline # Summary git log --reverse # Lists the commits from the oldest to the newest Viewing a commit git show 921a2ff # Shows the given commit git show HEAD # Shows the last commit git show HEAD~2 # Two steps before the last commit git show HEAD:file.js # Shows the version of file.js stored in the last commit Unstaging files (undoing git add) git restore --staged file.js # Copies the last version of file.js from repo to index Discarding local changes git restore file.js # Copies file.js from index to working directory git restore file1.js file2.js # Restores multiple files in working directory git restore. # Discards all local changes (except untracked files) git clean -fd # Removes all untracked files Restoring an earlier version of a file git restore --source=HEAD~2 file.js
Browsing History Viewing the history git log --stat # Shows the list of modified files git log --patch # Shows the actual changes (patches) Filtering the history git log -3 # Shows the last 3 entries git log --author=“Mosh” git log --before=“2020-08-17” git log --after=“one week ago” git log --grep=“GUI” # Commits with “GUI” in their message git log -S“GUI” # Commits with “GUI” in their patches git log hash1..hash2 # Range of commits git log file.txt # Commits that touched file.txt Formatting the log output git log --pretty=format:”%an committed %H” Creating an alias git config --global alias.lg “log --oneline" Viewing a commit git show HEAD~ git show HEAD~2:file1.txt # Shows the version of file stored in this commit Comparing commits git diff HEAD~2 HEAD # Shows the changes between two commits git diff HEAD~2 HEAD file.txt # Changes to file.txt only
Branching & Merging Managing branches git branch bugfix # Creates a new branch called bugfix git checkout bugfix # Switches to the bugfix branch git switch bugfix # Same as the above git switch -C bugfix # Creates and switches git branch -d bugfix # Deletes the bugfix branch Comparing branches git log master..bugfix # Lists the commits in the bugfix branch not in master git diff master..bugfix # Shows the summary of changes Stashing git stash push -m “New tax rules” # Creates a new stash git stash list # Lists all the stashes git stash show stash@{1} # Shows the given stash git stash show 1 # shortcut for stash@{1} git stash apply 1 # Applies the given stash to the working dir git stash drop 1 # Deletes the given stash git stash clear # Deletes all the stashes Merging git merge bugfix # Merges the bugfix branch into the current branch git merge --no-ff bugfix # Creates a merge commit even if FF is possible git merge --squash bugfix # Performs a squash merge git merge --abort # Aborts the merge
Viewing the merged branches git branch --merged # Shows the merged branches git branch --no-merged # Shows the unmerged branches Rebasing git rebase master # Changes the base of the current branch Cherry picking git cherry-pick dad47ed # Applies the given commit on the current branch
Rewriting History Undoing commits git reset --soft HEAD^ # Removes the last commit, keeps changed staged git reset --mixed HEAD^ # Unstages the changes as well git reset --hard HEAD^ # Discards local changes Reverting commits git revert 72856ea # Reverts the given commit git revert HEAD~3.. # Reverts the last three commits git revert --no-commit HEAD~3.. Recovering lost commits git reflog # Shows the history of HEAD git reflog show bugfix # Shows the history of bugfix pointer Amending the last commit git commit --amend Interactive rebasing git rebase -i HEAD~