SlideShare a Scribd company logo
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.
Ad

More Related Content

What's hot (20)

Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
Anurag Upadhaya
 
Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
Panagiotis Papadopoulos
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
Yan Vugenfirer
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
Nicolás Tourné
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to git
Emanuele Olivetti
 
Introduction git
Introduction gitIntroduction git
Introduction git
Dian Sigit Prastowo
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
Sage Sharp
 
Git
GitGit
Git
Shinu Suresh
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
Arnaud Seilles
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Lee Hanxue
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
Thomas Rausch
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
Arulmurugan Rajaraman
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
Senthilkumar Gopal
 
Github basics
Github basicsGithub basics
Github basics
Radoslav Georgiev
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
E Carter
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
Lukas Fittl
 
Git real slides
Git real slidesGit real slides
Git real slides
Lucas Couto
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
KMS Technology
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
Roland Emmanuel Salunga
 
git and github
git and githubgit and github
git and github
Darren Oakley
 

Viewers also liked (20)

Basic principles of Git
Basic principles of GitBasic principles of Git
Basic principles of Git
phuongvohuy
 
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
Katie Sylor-Miller
 
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...
Stowarzyszenie Jakości Systemów Informatycznych (SJSI)
 
Automated Tomcat Management
Automated Tomcat ManagementAutomated Tomcat Management
Automated Tomcat Management
seges
 
Ansible
AnsibleAnsible
Ansible
Jasim Muhammed
 
Mule management console installation with Tomcat
Mule management console installation with TomcatMule management console installation with Tomcat
Mule management console installation with Tomcat
Sudha Ch
 
Apache TomEE - Tomcat with a kick
Apache TomEE  - Tomcat with a kickApache TomEE  - Tomcat with a kick
Apache TomEE - Tomcat with a kick
Vishwanath Krishnamurthi
 
Tomcat
TomcatTomcat
Tomcat
abbadon1989
 
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
Daniel Cunha
 
Instalación de Apache Tomcat 8
Instalación de Apache Tomcat 8Instalación de Apache Tomcat 8
Instalación de Apache Tomcat 8
pablozacrosuarez
 
Git learning
Git learningGit learning
Git learning
Amit Gupta
 
Tomcat Clustering
Tomcat ClusteringTomcat Clustering
Tomcat Clustering
gouthamrv
 
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
Tomitribe
 
Git基礎介紹
Git基礎介紹Git基礎介紹
Git基礎介紹
Max Ma
 
Tomcat session clustering
Tomcat session clusteringTomcat session clustering
Tomcat session clustering
jgjhf lhhjfhdg
 
Web service introduction 2
Web service introduction 2Web service introduction 2
Web service introduction 2
Sagara Gunathunga
 
Tomcat next
Tomcat nextTomcat next
Tomcat next
Jean-Frederic Clere
 
Git 101 Presentation
Git 101 PresentationGit 101 Presentation
Git 101 Presentation
Scott Chacon
 
Git for joomla! development #JAB14
Git for joomla! development #JAB14Git for joomla! development #JAB14
Git for joomla! development #JAB14
Roberto Segura
 
Testy eksploracyjne - podstawy i przykłady
Testy eksploracyjne - podstawy i przykładyTesty eksploracyjne - podstawy i przykłady
Testy eksploracyjne - podstawy i przykłady
Radoslaw Smilgin
 
Basic principles of Git
Basic principles of GitBasic principles of Git
Basic principles of Git
phuongvohuy
 
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
Katie Sylor-Miller
 
Automated Tomcat Management
Automated Tomcat ManagementAutomated Tomcat Management
Automated Tomcat Management
seges
 
Mule management console installation with Tomcat
Mule management console installation with TomcatMule management console installation with Tomcat
Mule management console installation with Tomcat
Sudha 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 - 2014
Daniel Cunha
 
Instalación de Apache Tomcat 8
Instalación de Apache Tomcat 8Instalación de Apache Tomcat 8
Instalación de Apache Tomcat 8
pablozacrosuarez
 
Tomcat Clustering
Tomcat ClusteringTomcat Clustering
Tomcat Clustering
gouthamrv
 
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
Tomitribe
 
Git基礎介紹
Git基礎介紹Git基礎介紹
Git基礎介紹
Max Ma
 
Tomcat session clustering
Tomcat session clusteringTomcat session clustering
Tomcat session clustering
jgjhf lhhjfhdg
 
Git 101 Presentation
Git 101 PresentationGit 101 Presentation
Git 101 Presentation
Scott Chacon
 
Git for joomla! development #JAB14
Git for joomla! development #JAB14Git for joomla! development #JAB14
Git for joomla! development #JAB14
Roberto Segura
 
Testy eksploracyjne - podstawy i przykłady
Testy eksploracyjne - podstawy i przykładyTesty eksploracyjne - podstawy i przykłady
Testy eksploracyjne - podstawy i przykłady
Radoslaw Smilgin
 
Ad

Similar to Git tutorial (20)

GIT_In_90_Minutes
GIT_In_90_MinutesGIT_In_90_Minutes
GIT_In_90_Minutes
vimukthirandika
 
Git
GitGit
Git
Parag Gupta
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
srinathcox
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
Chris Johnson
 
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
Christoph Matthies
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
seungzzang Kim
 
Git
GitGit
Git
Gayan Kalanamith Mannapperuma
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
Tagged Social
 
SVN 2 Git
SVN 2 GitSVN 2 Git
SVN 2 Git
Marco De Stefano
 
Git
GitGit
Git
Omar Al-Sabek
 
Git
GitGit
Git
Hanokh Aloni
 
How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get Git
Susan Tan
 
git - the basics
git - the basicsgit - the basics
git - the basics
Arnelle Balane
 
Now i git it!!!
Now i git it!!!Now i git it!!!
Now i git it!!!
Yoram Michaeli
 
Git github
Git githubGit github
Git github
Anurag Deb
 
Git
GitGit
Git
AddWeb Solution Pvt. Ltd.
 
Git
GitGit
Git
Terry Wang
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
Terry Wang
 
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
Brian K. Vagnini
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
Terry Wang
 
Ad

Recently uploaded (20)

Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
Adobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREEAdobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREE
zafranwaqar90
 
Adobe Media Encoder Crack FREE Download 2025
Adobe Media Encoder  Crack FREE Download 2025Adobe Media Encoder  Crack FREE Download 2025
Adobe Media Encoder Crack FREE Download 2025
zafranwaqar90
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
Autodesk Inventor Crack (2025) Latest
Autodesk Inventor    Crack (2025) LatestAutodesk Inventor    Crack (2025) Latest
Autodesk Inventor Crack (2025) Latest
Google
 
Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025
Phil Eaton
 
Download MathType Crack Version 2025???
Download MathType Crack  Version 2025???Download MathType Crack  Version 2025???
Download MathType Crack Version 2025???
Google
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
sequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineeringsequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineering
aashrithakondapalli8
 
The Elixir Developer - All Things Open
The Elixir Developer - All Things OpenThe Elixir Developer - All Things Open
The Elixir Developer - All Things Open
Carlo Gilmar Padilla Santana
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.pptPassive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
IES VE
 
Beyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraftBeyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraft
Dmitrii Ivanov
 
GC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance EngineeringGC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance Engineering
Tier1 app
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
Adobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREEAdobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREE
zafranwaqar90
 
Adobe Media Encoder Crack FREE Download 2025
Adobe Media Encoder  Crack FREE Download 2025Adobe Media Encoder  Crack FREE Download 2025
Adobe Media Encoder Crack FREE Download 2025
zafranwaqar90
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
Autodesk Inventor Crack (2025) Latest
Autodesk Inventor    Crack (2025) LatestAutodesk Inventor    Crack (2025) Latest
Autodesk Inventor Crack (2025) Latest
Google
 
Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025
Phil Eaton
 
Download MathType Crack Version 2025???
Download MathType Crack  Version 2025???Download MathType Crack  Version 2025???
Download MathType Crack Version 2025???
Google
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
sequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineeringsequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineering
aashrithakondapalli8
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.pptPassive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
IES VE
 
Beyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraftBeyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraft
Dmitrii Ivanov
 
GC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance EngineeringGC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance Engineering
Tier1 app
 

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

  • #3: 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
  • #5: 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.
  • #6: 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
  • #8: 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
  • #18: 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.
  翻译: