SlideShare a Scribd company logo
1 of 32
Git Quick Tutorial
Pikicast R&D
Jack Pham
Git Commands
Setting up a repository init, clone, config
Saving changes add, commit
Inspecting a repository status, log
Navigate through commit and branch checkout
Undo changes checkout, revert, reset, clean
Rewriting history commit —ammend, rebase (rebase -i), reflog
Syncing remote, fetch, pull, push
Branching branch, checkout, merge
* Need to use with caution, should never be done on public(share) target
Setup a repository and
start working
init
clone
git vs svn
Git init
git init
git init --bare
git clone
Saving changes
add
commit
Git repository local
Working Directory Stage Area
File status
git add
git add
git commit
git rm
Tracked
Common Git Routine (Local)
- Edit-Stage-Commit
$vim hello.js
# Edit
$ git add hello.js
$ git commit
# Edit commit message
- Edit-Stage-Commit-Amend
# Edit hello.js
$ git add hello.js
$ git commit --amend
# Edit commit message
** Don’t amend commit that you already push to public repository
Viewing old commits
log
checkout
View log
$ git log
$ git log -n <limit>
$ git log --oneline
$ git log --stat
$ git log -p
$ git log --author=“<patterns>”
$ git log <file>
$ git log --graph --decorate --oneline
$ git log --grep=“<patterns>”
git checkout branch
git checkout master git checkout feature
git checkout commit
git checkout master
git checkout 81abc12
** Don’t commit your work on a detach head
Checkout options
git checkout <branch>
git checkout <commit>
git checkout <commit> <file>
Example:
git checkout master
git checkout a12ebd3
git checkout a12ebd3 hello.js
Undoing changes
checkout
revert
reset
git checkout to undo
git checkout a1e8fb5 # modify files
git add <file>
git commit
git revert <commit>
git revert abcd12ef
Before revert
After revert
abcd12ef
- The git revert command undoes a committed snapshot.
- Undo the changes introduced by the commit
- Appends a new commit with the resulting content.
- git revert doesn't alter history
git reset
abcd12ef abcd12ef
Before reset
After reset
- Variation:
- git reset <file> : remove from staging area
- git reset : reset branch to most recent commit (soft)
- git reset ——hard
- git reset <commit>
- git reset ——hard <commit>
- git revert is “safe” way to undo
- git reset “dangerous” to undo
** Don’t reset if you’ve already pushed to shared repository
revert vs reset
- Don’t alter history
- Safe way to undo but generate
more commit
- For undo shared/public commits
- Alter history
- unsafe way to undo
shared/public commits
- Cleaner history
- For undo private (non-public)
commits
Rewriting History
commit --amend
reflog
rebase
git commit --amend
- Modify last commit
- Replace last commit entirely
- Use to fix last commit (which hasn't pushed
to share repo)
- Variation
- git commit --amend
- git commit --amend --no-edit
** Don’t amend commit that you already push to public repository
git rebase <base>
- Rebasing is the process of moving a
branch to a new base commit.
- Maintain linear history
git rebase
git merge
git reflog
- What to do if you accidentally
- git reset --hard
- Reflog contain log of activity you perform
Remote synchronise
and branching
remote
pull
fetch
push
branch
merge
git remote
git remote
git remote -v
git remote add <name> <url>
git remote rm <name>
git remote rename <oldname> <new-name>
git fetch
- Download commits from remote but not merge to
local
- Give you opportunity to review
- Merge or rebase after review
git fetch <remote>
git fetch <remote> <branch>
git pull
git fetch
git merge
git pull = git fetch + git merge
git pull --rebase = git fetch + git rebase
- Download commits from remote and
merge (or rebase) to local branch
git push
transfer commits from your local
repository to a remote repo.
git push <remote>
git push <remote> —force
git push <remote> -all
git push <remote> --tags
** Do not use the --force flag unless you’re absolutely sure you know
what you’re doing.
git branch
Represented by a pointer (branch tip)
git branch
git branch <branch>
git branch -d <branch>
git branch -D <branch>
git branch -m <branch>
git merge
Putting forked history back together
git branch -m <branch>
git branch --no-ff <branch>
fast-forward
(git does this whenever possible)
non-fast-forward (3-ways merge)
(probably after rebase)
Cleaner history
- Private branch: rebase & fast-forward merge
- Share: 3-way merge
- Atomic commit and meaningful message
- Good naming convention
Staying out of troubles
- Don’t amend commit that you already shared
repository
- Don’t commit your work on a detached head
- Don’t reset if you’ve already pushed to shared
repository
- Don’t use the ‘push --force’ flag unless you’re
absolutely sure you know what you’re doing.

More Related Content

What's hot (20)

Git advanced
Git advancedGit advanced
Git advanced
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
 
Git slides
Git slidesGit slides
Git slides
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Git Introduction
Git IntroductionGit Introduction
Git Introduction
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Git commands
Git commandsGit commands
Git commands
 
Git basics
Git basicsGit basics
Git basics
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git Grundlagen
Git GrundlagenGit Grundlagen
Git Grundlagen
 
Learning git
Learning gitLearning git
Learning git
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
Version control system and Git
Version control system and GitVersion control system and Git
Version control system and Git
 
Introducción a git
Introducción a gitIntroducción a git
Introducción a git
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Inside GitHub with Chris Wanstrath
Inside GitHub with Chris WanstrathInside GitHub with Chris Wanstrath
Inside GitHub with Chris Wanstrath
 

Viewers also liked

Basic principles of Git
Basic principles of GitBasic principles of Git
Basic principles of Gitphuongvohuy
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messesKatie Sylor-Miller
 
Automated Tomcat Management
Automated Tomcat ManagementAutomated Tomcat Management
Automated Tomcat Managementseges
 
Mule management console installation with Tomcat
Mule management console installation with TomcatMule management console installation with Tomcat
Mule management console installation with TomcatSudha Ch
 
Java ee com apache tom ee e tomee+ tdc - 2014
Java ee com apache tom ee e tomee+   tdc - 2014Java ee com apache tom ee e tomee+   tdc - 2014
Java ee com apache tom ee e tomee+ tdc - 2014Daniel Cunha
 
Instalación de Apache Tomcat 8
Instalación de Apache Tomcat 8Instalación de Apache Tomcat 8
Instalación de Apache Tomcat 8pablozacrosuarez
 
Tomcat Clustering
Tomcat ClusteringTomcat Clustering
Tomcat Clusteringgouthamrv
 
Apache TomEE, Java EE 6 Web Profile {and more} on Tomcat
Apache TomEE, Java EE 6 Web Profile {and more} on TomcatApache TomEE, Java EE 6 Web Profile {and more} on Tomcat
Apache TomEE, Java EE 6 Web Profile {and more} on TomcatTomitribe
 
Git基礎介紹
Git基礎介紹Git基礎介紹
Git基礎介紹Max Ma
 
Tomcat session clustering
Tomcat session clusteringTomcat session clustering
Tomcat session clusteringKim SeokYoung
 
Git 101 Presentation
Git 101 PresentationGit 101 Presentation
Git 101 PresentationScott Chacon
 
Git for joomla! development #JAB14
Git for joomla! development #JAB14Git for joomla! development #JAB14
Git for joomla! development #JAB14Roberto Segura
 

Viewers also liked (20)

Basic principles of Git
Basic principles of GitBasic principles of Git
Basic principles of Git
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
Przyszłość ma na imię Mobile – testowanie i automatyzacja testów aplikacji mo...
Przyszłość ma na imię Mobile – testowanie i automatyzacja testów aplikacji mo...Przyszłość ma na imię Mobile – testowanie i automatyzacja testów aplikacji mo...
Przyszłość ma na imię Mobile – testowanie i automatyzacja testów aplikacji mo...
 
Automated Tomcat Management
Automated Tomcat ManagementAutomated Tomcat Management
Automated Tomcat Management
 
Ansible
AnsibleAnsible
Ansible
 
Mule management console installation with Tomcat
Mule management console installation with TomcatMule management console installation with Tomcat
Mule management console installation with Tomcat
 
Apache TomEE - Tomcat with a kick
Apache TomEE  - Tomcat with a kickApache TomEE  - Tomcat with a kick
Apache TomEE - Tomcat with a kick
 
Tomcat
TomcatTomcat
Tomcat
 
Java ee com apache tom ee e tomee+ tdc - 2014
Java ee com apache tom ee e tomee+   tdc - 2014Java ee com apache tom ee e tomee+   tdc - 2014
Java ee com apache tom ee e tomee+ tdc - 2014
 
Instalación de Apache Tomcat 8
Instalación de Apache Tomcat 8Instalación de Apache Tomcat 8
Instalación de Apache Tomcat 8
 
Git learning
Git learningGit learning
Git learning
 
Tomcat Clustering
Tomcat ClusteringTomcat Clustering
Tomcat Clustering
 
Apache TomEE, Java EE 6 Web Profile {and more} on Tomcat
Apache TomEE, Java EE 6 Web Profile {and more} on TomcatApache TomEE, Java EE 6 Web Profile {and more} on Tomcat
Apache TomEE, Java EE 6 Web Profile {and more} on Tomcat
 
Git基礎介紹
Git基礎介紹Git基礎介紹
Git基礎介紹
 
Tomcat session clustering
Tomcat session clusteringTomcat session clustering
Tomcat session clustering
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Web service introduction 2
Web service introduction 2Web service introduction 2
Web service introduction 2
 
Tomcat next
Tomcat nextTomcat next
Tomcat next
 
Git 101 Presentation
Git 101 PresentationGit 101 Presentation
Git 101 Presentation
 
Git for joomla! development #JAB14
Git for joomla! development #JAB14Git for joomla! development #JAB14
Git for joomla! development #JAB14
 

Similar to Git tutorial (20)

GIT_In_90_Minutes
GIT_In_90_MinutesGIT_In_90_Minutes
GIT_In_90_Minutes
 
Git
GitGit
Git
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Git Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierGit Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easier
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
 
Git
GitGit
Git
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
SVN 2 Git
SVN 2 GitSVN 2 Git
SVN 2 Git
 
Git
GitGit
Git
 
Git
GitGit
Git
 
How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get Git
 
git - the basics
git - the basicsgit - the basics
git - the basics
 
Now i git it!!!
Now i git it!!!Now i git it!!!
Now i git it!!!
 
Git github
Git githubGit github
Git github
 
Git
GitGit
Git
 
Git
GitGit
Git
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
 
Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615
 

Recently uploaded

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 

Recently uploaded (20)

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 

Git tutorial

  • 2. Git Commands Setting up a repository init, clone, config Saving changes add, commit Inspecting a repository status, log Navigate through commit and branch checkout Undo changes checkout, revert, reset, clean Rewriting history commit —ammend, rebase (rebase -i), reflog Syncing remote, fetch, pull, push Branching branch, checkout, merge * Need to use with caution, should never be done on public(share) target
  • 3. Setup a repository and start working init clone
  • 5. Git init git init git init --bare git clone
  • 8. Working Directory Stage Area File status git add git add git commit git rm Tracked
  • 9. Common Git Routine (Local) - Edit-Stage-Commit $vim hello.js # Edit $ git add hello.js $ git commit # Edit commit message - Edit-Stage-Commit-Amend # Edit hello.js $ git add hello.js $ git commit --amend # Edit commit message ** Don’t amend commit that you already push to public repository
  • 11. View log $ git log $ git log -n <limit> $ git log --oneline $ git log --stat $ git log -p $ git log --author=“<patterns>” $ git log <file> $ git log --graph --decorate --oneline $ git log --grep=“<patterns>”
  • 12. git checkout branch git checkout master git checkout feature
  • 13. git checkout commit git checkout master git checkout 81abc12 ** Don’t commit your work on a detach head
  • 14. Checkout options git checkout <branch> git checkout <commit> git checkout <commit> <file> Example: git checkout master git checkout a12ebd3 git checkout a12ebd3 hello.js
  • 16. git checkout to undo git checkout a1e8fb5 # modify files git add <file> git commit
  • 17. git revert <commit> git revert abcd12ef Before revert After revert abcd12ef - The git revert command undoes a committed snapshot. - Undo the changes introduced by the commit - Appends a new commit with the resulting content. - git revert doesn't alter history
  • 18. git reset abcd12ef abcd12ef Before reset After reset - Variation: - git reset <file> : remove from staging area - git reset : reset branch to most recent commit (soft) - git reset ——hard - git reset <commit> - git reset ——hard <commit> - git revert is “safe” way to undo - git reset “dangerous” to undo ** Don’t reset if you’ve already pushed to shared repository
  • 19. revert vs reset - Don’t alter history - Safe way to undo but generate more commit - For undo shared/public commits - Alter history - unsafe way to undo shared/public commits - Cleaner history - For undo private (non-public) commits
  • 21. git commit --amend - Modify last commit - Replace last commit entirely - Use to fix last commit (which hasn't pushed to share repo) - Variation - git commit --amend - git commit --amend --no-edit ** Don’t amend commit that you already push to public repository
  • 22. git rebase <base> - Rebasing is the process of moving a branch to a new base commit. - Maintain linear history git rebase git merge
  • 23. git reflog - What to do if you accidentally - git reset --hard - Reflog contain log of activity you perform
  • 25. git remote git remote git remote -v git remote add <name> <url> git remote rm <name> git remote rename <oldname> <new-name>
  • 26. git fetch - Download commits from remote but not merge to local - Give you opportunity to review - Merge or rebase after review git fetch <remote> git fetch <remote> <branch>
  • 27. git pull git fetch git merge git pull = git fetch + git merge git pull --rebase = git fetch + git rebase - Download commits from remote and merge (or rebase) to local branch
  • 28. git push transfer commits from your local repository to a remote repo. git push <remote> git push <remote> —force git push <remote> -all git push <remote> --tags ** Do not use the --force flag unless you’re absolutely sure you know what you’re doing.
  • 29. git branch Represented by a pointer (branch tip) git branch git branch <branch> git branch -d <branch> git branch -D <branch> git branch -m <branch>
  • 30. git merge Putting forked history back together git branch -m <branch> git branch --no-ff <branch> fast-forward (git does this whenever possible) non-fast-forward (3-ways merge) (probably after rebase)
  • 31. Cleaner history - Private branch: rebase & fast-forward merge - Share: 3-way merge - Atomic commit and meaningful message - Good naming convention
  • 32. Staying out of troubles - Don’t amend commit that you already shared repository - Don’t commit your work on a detached head - Don’t reset if you’ve already pushed to shared repository - Don’t use the ‘push --force’ flag unless you’re absolutely sure you know what you’re doing.

Editor's Notes

  1. Everyday git commands, should be familiar with these commands. This part will take you through a quick tour. For those who have use git: a reminder For those who new: a intro section, show what git is capable of
  2. Git is distributed, all the repos are equal, there is not special repo is set by git, git treat all repo the same Assign a role to git repo by conventions: we define the roles for those repos, and treat them as such. Collaboration via sync between repos.
  3. You can create git repo any where, but usually create one and clone Bare is repo without working copy (share, public repo) Dev’s repo is non-bare Dev don’t need create new repo, use clone
  4. Working directory is the dir where your files are in Staging area is the ‘virtual area’ contains the file (modified, changed) which you want to put in a commit .git is a folder contain history of your repo & repository-only settings
  5. The git revert command undoes a committed snapshot. it figures out how to undo the changes introduced by the commit and appends a new commit with the resulting content.