SlideShare a Scribd company logo
1 of 35
Git
What is Git?
Distributed version control system (DVCS)
SVN = Centralized version control system
Mercurial, Bazaar are other DVCS
Initially designed and developed by Linus
Torvalds to manage Linux kernel code base
when BitKeeper revoked free license.
SVN (Centralized VCS) overview
Git (Distributed VCS) overview
Git (Distributed VCS) overview
(cont)
Why Git?
Embraced by all major hosting sites:
Github, Google Code, CodePlex, BitBucket
Used by major projects
Linux kernel, Android, ASP.NET MVC,
Facebook, Eclipse, Twitter Boostrap, ...
• Able to work disconnected (ex. VPN / home)
o (Almost) everything is local, fast
o Log is always available
o Private workspace
 Able to commit whenever, create snapshots,
push when ready (off VPN, done hacking)
 Share when ready, ability to modify previous
commits before sharing
• Local branching, easily switch gears when
customer calls (isolate work units)
 features, bug fixes, proof of concepts, etc
Why Git? - Benefits
General workflow
File status lifecycle
Repository commits
Terms
HEAD
last commit of current branch
HEAD^
parent of HEAD
master
default development branch (trunk)
origin
default upstream repository (name of remote
when git clone was used)
Terms (cont.)
HEAD^ == HEAD~1 # parent of HEAD
HEAD^^^ == HEAD~3
master^^^ == master ~3
git init
New
git clone <url>
Existing
run at the project's top-most directory
creates a .git directory
Initializing
Review previous commit
git show --stat
git show --name-status
info about last commit
git show HEAD
git show HEAD^^^
git show master~10
git show @{yesterday}
git show master@{May.16}
Log
git log
git log --name-status
git log --oneline --graph --all
git log --author="Sean Lynch"
git log --grep="commit.*message.*text"
git log -- some/file
limit by changes to specific file
git timeline / git lol
custom aliases
Branching
git branch <branchname>
git checkout <branchname>
git checkout -b <branchname>
Create new branch and switch to
git branch [-a -l -r]
List branches (all, local, remote)
git merge <branchname>
Merge branch into current branch (ex. master)
Stashing
git stash
git stash [save message]
git stash list
git status apply
git stash clear
git stash branch <branchname>
Making a release (tagging)
git tag -a <name>
Create an annotated tag (with message)
git push --tags
Push tags to remote
git tag
list all tags
Remotes
git remote -v
git remote add <name> <url>
git remote show <name>
git branch --set-upstream master origin/master
Set local branch to track remote branch
git svn
http://git-scm.com/book/en/Git-and-Other-Systems-Git-
and-Subversion
Updating (Push/Pull)
git fetch / git merge
Fetch latest changes from origin, need to
use git merge to apply.
git pull
Pull latest changes from origin (fetch +
merge)
git push [remote_name] [branch_name]
Reverting
git checkout .
Revert changes to all files into working directory,
overwriting any local changes. This is most similar to
"svn revert"
git checkout -- <filename>
Revert changes to a file in working directory
git log --diff-filter=D -- <filename>
git checkout <deleting_commit>^ -- <filename>
Restore a deleted file
Reverting (cont.)
git reset HEAD
Unstage something
git reset HEAD^
forget about a commit, load it back into the staging area
git reset --hard HEAD / git checkout -f
Return to last committed state (discard all local
changes). Can not be undone (without reflog)
Reverting (cont. more)
git commit --amend
Change last commit (correct the previous commit, with
the staged changes)
git revert HEAD
Revert changes (creates a new commit)
Getting Started
Install
Configuration
Ignores
Install
Windows
Git for Windows: http://msysgit.github.com/
Git Extensions:
http://code.google.com/p/gitextensions/
TortoiseGit: http://code.google.com/p/tortoisegit/
Mac
Homebrew: brew install git bash-completion
SourceTree: http://www.sourcetreeapp.com/
GitHub for Mac: http://mac.github.com/
Configuration
git config --global user.name "Sean Lynch"
git config --global user.email "sean.lynch@sbcs.com"
git config --global core.autocrlf true #Windows
git config --global core.autocrlf input #Macs
git config --global color.ui true
git config --global log.decorate true
git config --list
cat ~/.gitconfig
Configuration (aliases)
git config --global alias.st status -s
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.timeline=log --graph --
pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s
%Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --
date=relative --all
Ignores
git config --global core.excludesfile
~/.gitignore_global
Collection of .gitignore templates by language /
framework
https://github.com/github/gitignore
Review
git init
git clone
git add
git status
git commit
git log
git branch
git checkout
git merge
git push
git fetch
git pull
Extras - Modifying history
git commit --amend
Modify previous commit. Useful to update
message or include missing file without
creating a new commit
git rebase -i
Rewrite history. Squash, reorder, by
dropping
Extras
git submodule
git subtree
Finding regressions
git bisect start
git bisect good <commit>
git bisect bad <commit>
git bisect visualize
git bisect reset
Best practices
Don't develop off master, use
develop/feature/issue/etc branches
Help / Documentation / Reference
git <command> --help
http://gitref.org/
http://git-scm.com/book
http://help.github.com/
http://www.codingdomain.com/git/tricks/
http://jonas.nitro.dk/git/quick-reference.html
http://gitimmersion.com/
http://marklodato.github.com/visual-git-guide/

More Related Content

What's hot

What's hot (19)

Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
Git intro hands on windows with msysgit
Git intro hands on windows with msysgitGit intro hands on windows with msysgit
Git intro hands on windows with msysgit
 
Git vs svn
Git vs svnGit vs svn
Git vs svn
 
Git is my hero
Git is my heroGit is my hero
Git is my hero
 
Now i git it!!!
Now i git it!!!Now i git it!!!
Now i git it!!!
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
 
GIT_In_90_Minutes
GIT_In_90_MinutesGIT_In_90_Minutes
GIT_In_90_Minutes
 
Git Basic
Git BasicGit Basic
Git Basic
 
SVN 2 Git
SVN 2 GitSVN 2 Git
SVN 2 Git
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
 
Git submodule
Git submoduleGit submodule
Git submodule
 
01 - Git vs SVN
01 - Git vs SVN01 - Git vs SVN
01 - Git vs SVN
 
Git
GitGit
Git
 
Git cli
Git cliGit cli
Git cli
 
Git introduction
Git introductionGit introduction
Git introduction
 
Introduction to GIT versioning
Introduction to GIT versioningIntroduction to GIT versioning
Introduction to GIT versioning
 
Svn vs mercurial vs github
Svn  vs  mercurial vs  githubSvn  vs  mercurial vs  github
Svn vs mercurial vs github
 
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
 

Similar to Git overview - DVCS fundamentals

Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践Terry Wang
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github Max Claus Nunes
 
Advanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with GitAdvanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with GitRasan Samarasinghe
 
Git cheat sheet
Git cheat sheetGit cheat sheet
Git cheat sheetLam Hoang
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubDSC GVP
 
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
 
HackMTY - GitHub Workshop
HackMTY - GitHub WorkshopHackMTY - GitHub Workshop
HackMTY - GitHub WorkshopLuis Lamadrid
 
GTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSourceGTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSourceForest Mars
 
CraftCamp for Students - Introduction to git
CraftCamp for Students - Introduction to gitCraftCamp for Students - Introduction to git
CraftCamp for Students - Introduction to gitcraftworkz
 
Understanding about git
Understanding about gitUnderstanding about git
Understanding about gitSothearin Ren
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmdsrinathcox
 

Similar to Git overview - DVCS fundamentals (20)

Git
GitGit
Git
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Advanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with GitAdvanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with Git
 
Git and github
Git and githubGit and github
Git and github
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Git cheat sheet
Git cheat sheetGit cheat sheet
Git cheat sheet
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
git - the basics
git - the basicsgit - the basics
git - the basics
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Introduction to GIT
Introduction to GITIntroduction to GIT
Introduction to GIT
 
HackMTY - GitHub Workshop
HackMTY - GitHub WorkshopHackMTY - GitHub Workshop
HackMTY - GitHub Workshop
 
GTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSourceGTFO: Git Theory For OpenSource
GTFO: Git Theory For OpenSource
 
What the Git? - WordCamp Atlanta
What the Git? - WordCamp AtlantaWhat the Git? - WordCamp Atlanta
What the Git? - WordCamp Atlanta
 
Git github
Git githubGit github
Git github
 
CraftCamp for Students - Introduction to git
CraftCamp for Students - Introduction to gitCraftCamp for Students - Introduction to git
CraftCamp for Students - Introduction to git
 
Git
GitGit
Git
 
Understanding about git
Understanding about gitUnderstanding about git
Understanding about git
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 

More from Hanokh Aloni

NWD Total commander for fun and profit!!!
NWD Total commander for fun and profit!!!NWD Total commander for fun and profit!!!
NWD Total commander for fun and profit!!!Hanokh Aloni
 
CI CD OPS WHATHAVEYOU
CI CD OPS WHATHAVEYOUCI CD OPS WHATHAVEYOU
CI CD OPS WHATHAVEYOUHanokh Aloni
 
How to write proper GIT commit messages.pptx
How to write proper GIT commit messages.pptxHow to write proper GIT commit messages.pptx
How to write proper GIT commit messages.pptxHanokh Aloni
 
Architectural kata 0 of n.pptx
Architectural kata 0 of n.pptxArchitectural kata 0 of n.pptx
Architectural kata 0 of n.pptxHanokh Aloni
 
Code smells (1).pptx
Code smells (1).pptxCode smells (1).pptx
Code smells (1).pptxHanokh Aloni
 
top developer mistakes
top developer mistakes top developer mistakes
top developer mistakes Hanokh Aloni
 
Things senior developers should know
Things senior developers should knowThings senior developers should know
Things senior developers should knowHanokh Aloni
 
Cynefin framework in software engineering
Cynefin framework in software engineeringCynefin framework in software engineering
Cynefin framework in software engineeringHanokh Aloni
 
Trunk based vs git flow
Trunk based vs git flowTrunk based vs git flow
Trunk based vs git flowHanokh Aloni
 
How to write unmaintainable code
How to write unmaintainable codeHow to write unmaintainable code
How to write unmaintainable codeHanokh Aloni
 
How i learned to stop worrying and love the logs
How i learned to stop worrying and love the logsHow i learned to stop worrying and love the logs
How i learned to stop worrying and love the logsHanokh Aloni
 
Game is ggj2018 presentation
Game is ggj2018 presentationGame is ggj2018 presentation
Game is ggj2018 presentationHanokh Aloni
 
Game is ggj2017 presentation
Game is ggj2017 presentationGame is ggj2017 presentation
Game is ggj2017 presentationHanokh Aloni
 
02 terms and issues
02 terms and issues02 terms and issues
02 terms and issuesHanokh Aloni
 

More from Hanokh Aloni (20)

NWD Total commander for fun and profit!!!
NWD Total commander for fun and profit!!!NWD Total commander for fun and profit!!!
NWD Total commander for fun and profit!!!
 
CI CD OPS WHATHAVEYOU
CI CD OPS WHATHAVEYOUCI CD OPS WHATHAVEYOU
CI CD OPS WHATHAVEYOU
 
How to write proper GIT commit messages.pptx
How to write proper GIT commit messages.pptxHow to write proper GIT commit messages.pptx
How to write proper GIT commit messages.pptx
 
Architectural kata 0 of n.pptx
Architectural kata 0 of n.pptxArchitectural kata 0 of n.pptx
Architectural kata 0 of n.pptx
 
Code smells (1).pptx
Code smells (1).pptxCode smells (1).pptx
Code smells (1).pptx
 
NWD the73js.pptx
NWD the73js.pptxNWD the73js.pptx
NWD the73js.pptx
 
top developer mistakes
top developer mistakes top developer mistakes
top developer mistakes
 
Things senior developers should know
Things senior developers should knowThings senior developers should know
Things senior developers should know
 
Cynefin framework in software engineering
Cynefin framework in software engineeringCynefin framework in software engineering
Cynefin framework in software engineering
 
Microservices
MicroservicesMicroservices
Microservices
 
Wcbpijwbpij new
Wcbpijwbpij newWcbpijwbpij new
Wcbpijwbpij new
 
Trunk based vs git flow
Trunk based vs git flowTrunk based vs git flow
Trunk based vs git flow
 
How to write unmaintainable code
How to write unmaintainable codeHow to write unmaintainable code
How to write unmaintainable code
 
How i learned to stop worrying and love the logs
How i learned to stop worrying and love the logsHow i learned to stop worrying and love the logs
How i learned to stop worrying and love the logs
 
Game is ggj2018 presentation
Game is ggj2018 presentationGame is ggj2018 presentation
Game is ggj2018 presentation
 
Microservices
MicroservicesMicroservices
Microservices
 
Game is ggj2017 presentation
Game is ggj2017 presentationGame is ggj2017 presentation
Game is ggj2017 presentation
 
02 terms and issues
02 terms and issues02 terms and issues
02 terms and issues
 
Sip introduction
Sip introductionSip introduction
Sip introduction
 
Tdd guide
Tdd guideTdd guide
Tdd guide
 

Recently uploaded

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 

Recently uploaded (20)

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Git overview - DVCS fundamentals

  • 1. Git
  • 2. What is Git? Distributed version control system (DVCS) SVN = Centralized version control system Mercurial, Bazaar are other DVCS Initially designed and developed by Linus Torvalds to manage Linux kernel code base when BitKeeper revoked free license.
  • 5. Git (Distributed VCS) overview (cont)
  • 6. Why Git? Embraced by all major hosting sites: Github, Google Code, CodePlex, BitBucket Used by major projects Linux kernel, Android, ASP.NET MVC, Facebook, Eclipse, Twitter Boostrap, ...
  • 7. • Able to work disconnected (ex. VPN / home) o (Almost) everything is local, fast o Log is always available o Private workspace  Able to commit whenever, create snapshots, push when ready (off VPN, done hacking)  Share when ready, ability to modify previous commits before sharing • Local branching, easily switch gears when customer calls (isolate work units)  features, bug fixes, proof of concepts, etc Why Git? - Benefits
  • 11. Terms HEAD last commit of current branch HEAD^ parent of HEAD master default development branch (trunk) origin default upstream repository (name of remote when git clone was used)
  • 12. Terms (cont.) HEAD^ == HEAD~1 # parent of HEAD HEAD^^^ == HEAD~3 master^^^ == master ~3
  • 13. git init New git clone <url> Existing run at the project's top-most directory creates a .git directory Initializing
  • 14. Review previous commit git show --stat git show --name-status info about last commit git show HEAD git show HEAD^^^ git show master~10 git show @{yesterday} git show master@{May.16}
  • 15. Log git log git log --name-status git log --oneline --graph --all git log --author="Sean Lynch" git log --grep="commit.*message.*text" git log -- some/file limit by changes to specific file git timeline / git lol custom aliases
  • 16. Branching git branch <branchname> git checkout <branchname> git checkout -b <branchname> Create new branch and switch to git branch [-a -l -r] List branches (all, local, remote) git merge <branchname> Merge branch into current branch (ex. master)
  • 17. Stashing git stash git stash [save message] git stash list git status apply git stash clear git stash branch <branchname>
  • 18. Making a release (tagging) git tag -a <name> Create an annotated tag (with message) git push --tags Push tags to remote git tag list all tags
  • 19. Remotes git remote -v git remote add <name> <url> git remote show <name> git branch --set-upstream master origin/master Set local branch to track remote branch git svn http://git-scm.com/book/en/Git-and-Other-Systems-Git- and-Subversion
  • 20. Updating (Push/Pull) git fetch / git merge Fetch latest changes from origin, need to use git merge to apply. git pull Pull latest changes from origin (fetch + merge) git push [remote_name] [branch_name]
  • 21. Reverting git checkout . Revert changes to all files into working directory, overwriting any local changes. This is most similar to "svn revert" git checkout -- <filename> Revert changes to a file in working directory git log --diff-filter=D -- <filename> git checkout <deleting_commit>^ -- <filename> Restore a deleted file
  • 22. Reverting (cont.) git reset HEAD Unstage something git reset HEAD^ forget about a commit, load it back into the staging area git reset --hard HEAD / git checkout -f Return to last committed state (discard all local changes). Can not be undone (without reflog)
  • 23. Reverting (cont. more) git commit --amend Change last commit (correct the previous commit, with the staged changes) git revert HEAD Revert changes (creates a new commit)
  • 25. Install Windows Git for Windows: http://msysgit.github.com/ Git Extensions: http://code.google.com/p/gitextensions/ TortoiseGit: http://code.google.com/p/tortoisegit/ Mac Homebrew: brew install git bash-completion SourceTree: http://www.sourcetreeapp.com/ GitHub for Mac: http://mac.github.com/
  • 26. Configuration git config --global user.name "Sean Lynch" git config --global user.email "sean.lynch@sbcs.com" git config --global core.autocrlf true #Windows git config --global core.autocrlf input #Macs git config --global color.ui true git config --global log.decorate true git config --list cat ~/.gitconfig
  • 27. Configuration (aliases) git config --global alias.st status -s git config --global alias.co checkout git config --global alias.br branch git config --global alias.ci commit git config --global alias.timeline=log --graph -- pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit -- date=relative --all
  • 28. Ignores git config --global core.excludesfile ~/.gitignore_global Collection of .gitignore templates by language / framework https://github.com/github/gitignore
  • 29. Review git init git clone git add git status git commit git log git branch git checkout git merge git push git fetch git pull
  • 30. Extras - Modifying history git commit --amend Modify previous commit. Useful to update message or include missing file without creating a new commit git rebase -i Rewrite history. Squash, reorder, by dropping
  • 32. Finding regressions git bisect start git bisect good <commit> git bisect bad <commit> git bisect visualize git bisect reset
  • 33. Best practices Don't develop off master, use develop/feature/issue/etc branches
  • 34.
  • 35. Help / Documentation / Reference git <command> --help http://gitref.org/ http://git-scm.com/book http://help.github.com/ http://www.codingdomain.com/git/tricks/ http://jonas.nitro.dk/git/quick-reference.html http://gitimmersion.com/ http://marklodato.github.com/visual-git-guide/

Editor's Notes

  1. Uses hashes (SHA1) instead of incrementing version numbers due to no central authority
  2. Push full history to another server / remote ex. Start developing locally, then decide to push to server, Github, Google Code, etc. Later decide to change remote (switch from Google Code to Github, etc)
  3. staging area == index working directory == working tree local repo, HEAD remote repo, origin
  4. http://git-scm.com/book/en/Git-Branching-What-a-Branch-Is
  5. HEAD parent of next commit
  6. git init == svnadmin create <repo> git clone <url> == svn checkout <url> Later add remote if "git init" used git remote add origin git@github.com:username/Hello-World.git git pull -u origin master
  7. git show == git show HEAD git show --name-status ~= git diff HEAD^ --name-status
  8. git timeline is an alias for git log with flags git log == git log HEAD git log branchB..branchA git log branchA ^branchB show me commits reachable by branchA that are not reachable by branchB git log master..wiki git log wiki ^master git log master.. # HEAD of current branch show me the commits in my wiki branch not in master git log origin/master ^master git log ..@{u} get incoming (need to do a fetch first). What is on master branch on remote/server not in working context git log ^master origin/master git log @{u}.. get outgoing (all commits committed not yet pushed)
  9. One working directory for all branches, fast context switching (git checkout), not like SVN (one for trunk, one for each branch, etc) git branch <branchname> <start-point> git branch -t <branchname> <start-point> git reset --merge Cancel a conflicting merge (In git 1.7.0 or later) git merge --ff-only Fast forward merge only. Guarantees no conflicts. Means branch must have already merged up to HEAD of current branch git branch <branchname> <sha1> git checkout -b <branchname> <sha1> Create a branch from a commit (sha1). checkout will also automatically switch/checkout to new branch git branch <branchname> <sha1> git fetch git reset --HARD origin/master Create branch at current master/HEAD, and the move master/HEAD to origin/master. Helpful if master has diverged from origin/master, and you want to sync up with master and then merge in your changes slowly. == Branching and Merging == List: git branch Create: git branch testing Checkout: git checkout testing # work, make some commits Back: git checkout master Merge: git merge testing Create: git checkout -b new-branch Delete: git branch -d new-branch git merge origin/master Checkout remote branch (not already checked out) and track git checkout -t origin/develop http://gitready.com/intermediate/2009/01/09/checkout-remote-tracked-branch.html
  10. If need to change branches with outstanding changes
  11. http://www.codingdomain.com/git/tricks/
  12. remote = alias for url git branch --set-upstream master origin/master What git clone does by default for master git remote set-branches origin master my_other_branch Replace any branches currently being tracked and now track "master" and "my_other_branch" git remote set-branches origin --add my_new_branch Add "my_new_branch" as a tracking branch (doesn't remote existing) git branch foo origin/foo git push git push origin master git push origin [branchname] Can use Subversion as a remote
  13. git fetch is helpful to update local copy of logs, etc git pull == svn update
  14. replaces the changes in your working tree with the last content in HEAD. Changes already added to the index, as well as new files, will be kept http://gitready.com/beginner/2009/01/11/reverting-files.html http://www.cheatography.com/samcollett/cheat-sheets/git/ http://www.codingdomain.com/git/tricks/ http://cheat.errtheblog.com/s/git/ http://bryan-murdock.blogspot.com/2007/07/git-revert-is-not-equivalent-to-svn.html
  15. git reset HEAD == git reset --mixed HEAD http://git-scm.com/2011/07/11/reset.html http://stackoverflow.com/questions/927358/git-undo-last-commit
  16. More: http://git-scm.com/downloads/guis
  17. http://help.github.com/line-endings/ # http://stackoverflow.com/questions/231211/using-git-how-do-i-find-modified-files-between-local-and-remote git config --global alias.incoming '!git remote update -p; git log ..@{u}' git config --global alias.outgoing 'log @{u}..'
  18. http://help.github.com/ignore-files/
  19. http://gitref.org/
  20. Anything in the master branch should always be deployable http://nvie.com/posts/a-successful-git-branching-model/ http://justinhileman.info/article/changing-history/ git-flow
  21. Workflow http://nvie.com/posts/a-successful-git-branching-model/