SlideShare a Scribd company logo
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
Check out the links below to master the coding skills you need:
https://codewithmosh.com
https://youtube.com/user/programmingwithmosh
https://twitter.com/moshhamedani
https://facebook.com/programmingwithmosh/
Hi! My name is Mosh Hamedani. I’m a software engineer with
two decades of experience. I’ve taught millions of people how
to code or how to become a professional software engineer
through my YouTube channel and online coding school. It’s my
mission to make software engineering simple and accessible
to everyone.
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/
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
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~2
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
Checking out a commit
git checkout dad47ed # Checks out the given commit
git checkout master # Checks out the master branch
Finding a bad commit
git bisect start
git bisect bad # Marks the current commit as a bad commit
git bisect good ca49180 # Marks the given commit as a good commit
git bisect reset # Terminates the bisect session
Finding contributors
git shortlog
Viewing the history of a file
git log file.txt # Shows the commits that touched file.txt
git log --stat file.txt # Shows statistics (the number of changes) for file.txt
git log --patch file.txt # Shows the patches (changes) applied to file.txt
Finding the author of lines
git blame file.txt # Shows the author of each line in file.txt
Tagging
git tag v1.0 # Tags the last commit as v1.0
git tag v1.0 5e7a828 # Tags an earlier commit
git tag # Lists all the tags
git tag -d v1.0 # Deletes the given tag
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
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~5

More Related Content

What's hot

IntuneとWSUSを使ってWindows Updateをやってみる。
IntuneとWSUSを使ってWindows Updateをやってみる。IntuneとWSUSを使ってWindows Updateをやってみる。
IntuneとWSUSを使ってWindows Updateをやってみる。
shotayamamura1
 
HCL Sametime V11 installation - tips
HCL Sametime V11 installation - tipsHCL Sametime V11 installation - tips
HCL Sametime V11 installation - tips
Ales Lichtenberg
 
Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...
Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...
Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...
XavierPestel
 
Azure AD DSドメインに仮想マシンを参加させる
Azure AD DSドメインに仮想マシンを参加させるAzure AD DSドメインに仮想マシンを参加させる
Azure AD DSドメインに仮想マシンを参加させる
Tetsuya Yokoyama
 
Mementopython3 english
Mementopython3 englishMementopython3 english
Mementopython3 english
ssuser442080
 
Docker, LinuX Container
Docker, LinuX ContainerDocker, LinuX Container
Docker, LinuX Container
Araf Karsh Hamid
 
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
Seok-joon Yun
 
Servlet 3.1 Async I/O
Servlet 3.1 Async I/OServlet 3.1 Async I/O
Servlet 3.1 Async I/O
Simone Bordet
 
Java Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner WalkthroughJava Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner Walkthrough
Mahfuz Islam Bhuiyan
 
10 Tips for AIX Security
10 Tips for AIX Security10 Tips for AIX Security
10 Tips for AIX Security
HelpSystems
 
NSG フローログを支える技術 - NVF Advanced Flow Logging
NSG フローログを支える技術 - NVF Advanced Flow LoggingNSG フローログを支える技術 - NVF Advanced Flow Logging
NSG フローログを支える技術 - NVF Advanced Flow Logging
順也 山口
 
HTTP - The Other Face Of Domino
HTTP - The Other Face Of DominoHTTP - The Other Face Of Domino
HTTP - The Other Face Of Domino
Gabriella Davis
 
第6回「VMware vSphere 5」(2011/08/11 on しすなま!)
第6回「VMware vSphere 5」(2011/08/11 on しすなま!)第6回「VMware vSphere 5」(2011/08/11 on しすなま!)
第6回「VMware vSphere 5」(2011/08/11 on しすなま!)
System x 部 (生!) : しすなま! @ Lenovo Enterprise Solutions Ltd.
 
Enable Domino Data Access Services (DAS)
Enable Domino Data Access Services (DAS)Enable Domino Data Access Services (DAS)
Enable Domino Data Access Services (DAS)
Slobodan Lohja
 
Welcome to JanusCon! -- Past, Present and Future of Janus
Welcome to JanusCon! -- Past, Present and Future of JanusWelcome to JanusCon! -- Past, Present and Future of Janus
Welcome to JanusCon! -- Past, Present and Future of Janus
Lorenzo Miniero
 
Phrasal Verbs project
Phrasal Verbs projectPhrasal Verbs project
Phrasal Verbs projectangeltrabajos
 
The FPDF Library
The FPDF LibraryThe FPDF Library
The FPDF Library
Dave Ross
 
게임을 위한 최적의 AWS DB 서비스 소개 Dynamo DB, Aurora - 이종립 / Principle Enterprise Evang...
게임을 위한 최적의 AWS DB 서비스 소개 Dynamo DB, Aurora - 이종립 / Principle Enterprise Evang...게임을 위한 최적의 AWS DB 서비스 소개 Dynamo DB, Aurora - 이종립 / Principle Enterprise Evang...
게임을 위한 최적의 AWS DB 서비스 소개 Dynamo DB, Aurora - 이종립 / Principle Enterprise Evang...
BESPIN GLOBAL
 
Terraform: Infrastructure as Code
Terraform: Infrastructure as CodeTerraform: Infrastructure as Code
Terraform: Infrastructure as Code
Pradeep Bhadani
 

What's hot (20)

IntuneとWSUSを使ってWindows Updateをやってみる。
IntuneとWSUSを使ってWindows Updateをやってみる。IntuneとWSUSを使ってWindows Updateをやってみる。
IntuneとWSUSを使ってWindows Updateをやってみる。
 
HCL Sametime V11 installation - tips
HCL Sametime V11 installation - tipsHCL Sametime V11 installation - tips
HCL Sametime V11 installation - tips
 
Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...
Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...
Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...
 
Azure AD DSドメインに仮想マシンを参加させる
Azure AD DSドメインに仮想マシンを参加させるAzure AD DSドメインに仮想マシンを参加させる
Azure AD DSドメインに仮想マシンを参加させる
 
Mementopython3 english
Mementopython3 englishMementopython3 english
Mementopython3 english
 
Docker, LinuX Container
Docker, LinuX ContainerDocker, LinuX Container
Docker, LinuX Container
 
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
[2015-06-12] Oracle 성능 최적화 및 품질 고도화 1
 
Servlet 3.1 Async I/O
Servlet 3.1 Async I/OServlet 3.1 Async I/O
Servlet 3.1 Async I/O
 
Java Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner WalkthroughJava Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner Walkthrough
 
10 Tips for AIX Security
10 Tips for AIX Security10 Tips for AIX Security
10 Tips for AIX Security
 
NSG フローログを支える技術 - NVF Advanced Flow Logging
NSG フローログを支える技術 - NVF Advanced Flow LoggingNSG フローログを支える技術 - NVF Advanced Flow Logging
NSG フローログを支える技術 - NVF Advanced Flow Logging
 
HTTP - The Other Face Of Domino
HTTP - The Other Face Of DominoHTTP - The Other Face Of Domino
HTTP - The Other Face Of Domino
 
第6回「VMware vSphere 5」(2011/08/11 on しすなま!)
第6回「VMware vSphere 5」(2011/08/11 on しすなま!)第6回「VMware vSphere 5」(2011/08/11 on しすなま!)
第6回「VMware vSphere 5」(2011/08/11 on しすなま!)
 
Enable Domino Data Access Services (DAS)
Enable Domino Data Access Services (DAS)Enable Domino Data Access Services (DAS)
Enable Domino Data Access Services (DAS)
 
Welcome to JanusCon! -- Past, Present and Future of Janus
Welcome to JanusCon! -- Past, Present and Future of JanusWelcome to JanusCon! -- Past, Present and Future of Janus
Welcome to JanusCon! -- Past, Present and Future of Janus
 
Monografia-Devops
Monografia-DevopsMonografia-Devops
Monografia-Devops
 
Phrasal Verbs project
Phrasal Verbs projectPhrasal Verbs project
Phrasal Verbs project
 
The FPDF Library
The FPDF LibraryThe FPDF Library
The FPDF Library
 
게임을 위한 최적의 AWS DB 서비스 소개 Dynamo DB, Aurora - 이종립 / Principle Enterprise Evang...
게임을 위한 최적의 AWS DB 서비스 소개 Dynamo DB, Aurora - 이종립 / Principle Enterprise Evang...게임을 위한 최적의 AWS DB 서비스 소개 Dynamo DB, Aurora - 이종립 / Principle Enterprise Evang...
게임을 위한 최적의 AWS DB 서비스 소개 Dynamo DB, Aurora - 이종립 / Principle Enterprise Evang...
 
Terraform: Infrastructure as Code
Terraform: Infrastructure as CodeTerraform: Infrastructure as Code
Terraform: Infrastructure as Code
 

Similar to Git cheat-sheet

Git for beginners
Git for beginnersGit for beginners
Git for beginners
Arulmurugan Rajaraman
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
Tagged Social
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
seungzzang Kim
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
Senthilkumar Gopal
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
Ananth Kumar
 
Git basic
Git basicGit basic
Git basic
Akbar Uddin
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
9 series
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commands
Zakaria Bouazza
 
آموزش کار با GIT
آموزش کار با GITآموزش کار با GIT
Git github
Git githubGit github
Git github
Anurag Deb
 
Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheet
Abdul Basit
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
Prakash Dantuluri
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
Safique Ahmed Faruque
 
Improving your workflow with git
Improving your workflow with gitImproving your workflow with git
Improving your workflow with git
Dídac Ríos
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
gdsc13
 
Git learning
Git learningGit learning
Git learning
Amit Gupta
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践Terry Wang
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践Terry Wang
 
Git
GitGit

Similar to Git cheat-sheet (20)

Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git basic
Git basicGit basic
Git basic
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commands
 
آموزش کار با GIT
آموزش کار با GITآموزش کار با GIT
آموزش کار با GIT
 
Git github
Git githubGit github
Git github
 
Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheet
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Improving your workflow with git
Improving your workflow with gitImproving your workflow with git
Improving your workflow with git
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Git learning
Git learningGit learning
Git learning
 
Git
GitGit
Git
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
 
Git
GitGit
Git
 

Recently uploaded

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 

Recently uploaded (20)

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 

Git cheat-sheet

  • 1. Git Cheat Sheet The essential Git commands every developer must know
  • 2. 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
  • 3. Check out the links below to master the coding skills you need: https://codewithmosh.com https://youtube.com/user/programmingwithmosh https://twitter.com/moshhamedani https://facebook.com/programmingwithmosh/ Hi! My name is Mosh Hamedani. I’m a software engineer with two decades of experience. I’ve taught millions of people how to code or how to become a professional software engineer through my YouTube channel and online coding school. It’s my mission to make software engineering simple and accessible to everyone.
  • 4. 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/
  • 5. Table of Content Creating Snapshots 6 Browsing History 8 Branching & Merging 10 Collaboration 12 Rewriting History 13
  • 6. 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
  • 7. 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
  • 8. 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~2 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
  • 9. Checking out a commit git checkout dad47ed # Checks out the given commit git checkout master # Checks out the master branch Finding a bad commit git bisect start git bisect bad # Marks the current commit as a bad commit git bisect good ca49180 # Marks the given commit as a good commit git bisect reset # Terminates the bisect session Finding contributors git shortlog Viewing the history of a file git log file.txt # Shows the commits that touched file.txt git log --stat file.txt # Shows statistics (the number of changes) for file.txt git log --patch file.txt # Shows the patches (changes) applied to file.txt Finding the author of lines git blame file.txt # Shows the author of each line in file.txt Tagging git tag v1.0 # Tags the last commit as v1.0 git tag v1.0 5e7a828 # Tags an earlier commit git tag # Lists all the tags git tag -d v1.0 # Deletes the given tag
  • 10. 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
  • 11. 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
  • 12. 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
  • 13. 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~5