Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Git Cheat Sheet, Slides of History

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

2021/2022

Uploaded on 07/05/2022

allan.dev
allan.dev 🇦🇺

4.5

(85)

1K documents

Partial preview of the text

Download Git Cheat Sheet and more Slides History in PDF only on Docsity! Git Cheat Sheet The essential Git commands every developer must know 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 Table of Content Creating Snapshots 6 Browsing History 8 Branching & Merging 10 Collaboration 12 Rewriting History 13 Creating Snapshots Initializing a repository git init 
 Staging files git add file1.js # Stages a single file git add file1.js file2.js # Stages multiple files
 git add *.js # Stages with a pattern
 git add . # Stages the current directory and all its content Viewing the status 
 git status # Full status git status -s # Short status 
 Committing the staged files 
 git commit -m “Message” # Commits with a one-line message git commit # Opens the default editor to type a long message Skipping the staging area 
 git commit -am “Message” Removing files
 git rm file1.js # Removes from working directory and staging area 
 git rm --cached file1.js # Removes from staging area only Renaming or moving files 
 git mv file1.js file1.txt 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 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 Collaboration Cloning a repository git clone url Syncing with remotes git fetch origin master # Fetches master from origin git fetch origin # Fetches all objects from origin git fetch # Shortcut for “git fetch origin” git pull # Fetch + merge git push origin master # Pushes master to origin git push # Shortcut for “git push origin master” Sharing tags git push origin v1.0 # Pushes tag v1.0 to origin git push origin —delete v1.0 Sharing branches git branch -r # Shows remote tracking branches git branch -vv # Shows local & remote tracking branches git push -u origin bugfix # Pushes bugfix to origin git push -d origin bugfix # Removes bugfix from origin Managing remotes git remote # Shows remote repos git remote add upstream url # Adds a new remote called upstream git remote rm upstream # Remotes upstream
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved