SlideShare a Scribd company logo

Advanced Git Tutorial

Sage Sharp
Sage Sharp
Sage SharpDiversity and Inclusion consultant, Python & Django developer at Otter Tech

Do you know the basics of Git but wonder what all the hype is about? Do you want the ultimate control over your Git history? This tutorial will walk you through the basics of committing changes before diving into the more advanced and "dangerous" Git commands. Git is an open source, distributed version control system used to track many different projects. You can use it to manage anything from a personal notes directory to a multi-programmer project. This tutorial provides a short walk through of basic git commands and the Git philosophy to project management. Then we’ll dive into an exploration of the more advanced and “dangerous” Git commands. Watch as we rewrite our repository history, track bugs down to a specific commit, and untangle commits into an LKML-worthy patchset.

Advanced Git Tutorial

1 of 42
Download to read offline
Advanced Git Tutorial
   by Sarah Sharp
WARNING:
I am a unique snowflake
WARNING:
This tutorial may make you lazy
WARNING:
Some Git features are
    dangerous!
What is Git?


●   Distributed
●   Fast
●   Flexible
Git Basics
●       See Everyday Git Tutorial:
    –   http://www.kernel.org/pub/software/scm/git/doc
        s/everyday.html
●       My git commands:
    –   git add       - git commit
    –   git diff      - git log      - git show
    –   git push      - git pull
    –   git fetch     - git rebase
Ad

Recommended

More Related Content

What's hot (20)

Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By Swawibe
 
Git advanced
Git advancedGit advanced
Git advanced
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
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
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
 
git and github
git and githubgit and github
git and github
 
Git basics
Git basicsGit basics
Git basics
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
 
Git
GitGit
Git
 
Git
GitGit
Git
 
Grokking opensource with github
Grokking opensource with githubGrokking opensource with github
Grokking opensource with github
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 

Viewers also liked

Advanced Git
Advanced GitAdvanced Git
Advanced Gitsegv
 
Getting Git Right
Getting Git RightGetting Git Right
Getting Git RightSven Peters
 
Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to gitJoel Krebs
 
Energy Strategy Group_Report 2012 efficienza energetica
Energy Strategy Group_Report 2012 efficienza energeticaEnergy Strategy Group_Report 2012 efficienza energetica
Energy Strategy Group_Report 2012 efficienza energeticaEugenio Bacile di Castiglione
 
Secure PIN Management How to Issue and Change PINs Securely over the Web
Secure PIN Management How to Issue and Change PINs Securely over the WebSecure PIN Management How to Issue and Change PINs Securely over the Web
Secure PIN Management How to Issue and Change PINs Securely over the WebSafeNet
 
Alta White Paper D2C eCommerce Case Study 2016
Alta White Paper D2C eCommerce Case Study 2016Alta White Paper D2C eCommerce Case Study 2016
Alta White Paper D2C eCommerce Case Study 2016Patrick Nicholson
 
Diarrhea:Myths and facts, Precaution
Diarrhea:Myths and facts, Precaution Diarrhea:Myths and facts, Precaution
Diarrhea:Myths and facts, Precaution Wuzna Haroon
 
Enterprise workspaces - Extending SAP NetWeaver Portal capabilities
Enterprise workspaces - Extending SAP NetWeaver Portal capabilities Enterprise workspaces - Extending SAP NetWeaver Portal capabilities
Enterprise workspaces - Extending SAP NetWeaver Portal capabilities SAP Portal
 

Viewers also liked (14)

Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Getting Git Right
Getting Git RightGetting Git Right
Getting Git Right
 
Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to git
 
Energy Strategy Group_Report 2012 efficienza energetica
Energy Strategy Group_Report 2012 efficienza energeticaEnergy Strategy Group_Report 2012 efficienza energetica
Energy Strategy Group_Report 2012 efficienza energetica
 
Secure PIN Management How to Issue and Change PINs Securely over the Web
Secure PIN Management How to Issue and Change PINs Securely over the WebSecure PIN Management How to Issue and Change PINs Securely over the Web
Secure PIN Management How to Issue and Change PINs Securely over the Web
 
"15 Business Story Ideas to Jump on Now"
"15 Business Story Ideas to Jump on Now""15 Business Story Ideas to Jump on Now"
"15 Business Story Ideas to Jump on Now"
 
Basics of Coding in Pediatrics Medical Billing
Basics of Coding in Pediatrics Medical BillingBasics of Coding in Pediatrics Medical Billing
Basics of Coding in Pediatrics Medical Billing
 
Credit cards
Credit cardsCredit cards
Credit cards
 
Alta White Paper D2C eCommerce Case Study 2016
Alta White Paper D2C eCommerce Case Study 2016Alta White Paper D2C eCommerce Case Study 2016
Alta White Paper D2C eCommerce Case Study 2016
 
cathy resume
cathy resumecathy resume
cathy resume
 
Information från Läkemedelsverket #5 2013
Information från Läkemedelsverket #5 2013Information från Läkemedelsverket #5 2013
Information från Läkemedelsverket #5 2013
 
Nt1310 project
Nt1310 projectNt1310 project
Nt1310 project
 
Diarrhea:Myths and facts, Precaution
Diarrhea:Myths and facts, Precaution Diarrhea:Myths and facts, Precaution
Diarrhea:Myths and facts, Precaution
 
Enterprise workspaces - Extending SAP NetWeaver Portal capabilities
Enterprise workspaces - Extending SAP NetWeaver Portal capabilities Enterprise workspaces - Extending SAP NetWeaver Portal capabilities
Enterprise workspaces - Extending SAP NetWeaver Portal capabilities
 

Similar to Advanced Git Tutorial

The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of GitDivineOmega
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptuallyseungzzang Kim
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践Terry Wang
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践Terry Wang
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitAmit Mathur
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practiceMajid Hosseini
 
Git tech talk
Git tech talkGit tech talk
Git tech talkrazasayed
 
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 with the flow
Git with the flowGit with the flow
Git with the flowDana White
 
Getting some Git
Getting some GitGetting some Git
Getting some GitBADR
 

Similar to Advanced Git Tutorial (20)

The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
 
Git and github introduction
Git and github introductionGit and github introduction
Git and github introduction
 
Git
GitGit
Git
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
 
Advanted git
Advanted git Advanted git
Advanted git
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Git tech talk
Git tech talkGit tech talk
Git tech talk
 
Introduction to GIT
Introduction to GITIntroduction to GIT
Introduction to GIT
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
Git with the flow
Git with the flowGit with the flow
Git with the flow
 
Git
GitGit
Git
 
Git introduction
Git introductionGit introduction
Git introduction
 
Git basic
Git basicGit basic
Git basic
 
Git github
Git githubGit github
Git github
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
Getting some Git
Getting some GitGetting some Git
Getting some Git
 

More from Sage Sharp

Countering impostor syndrome culture
Countering impostor syndrome cultureCountering impostor syndrome culture
Countering impostor syndrome cultureSage Sharp
 
Countering impostor syndrome culture
Countering impostor syndrome cultureCountering impostor syndrome culture
Countering impostor syndrome cultureSage Sharp
 
Herding cats with django
Herding cats with djangoHerding cats with django
Herding cats with djangoSage Sharp
 
Open source 101 for students
Open source 101 for studentsOpen source 101 for students
Open source 101 for studentsSage Sharp
 
Small, smaller, smallest: A Tour of the Embedded World
Small, smaller, smallest: A Tour of the Embedded WorldSmall, smaller, smallest: A Tour of the Embedded World
Small, smaller, smallest: A Tour of the Embedded WorldSage Sharp
 
Linux Kernel Introduction
Linux Kernel IntroductionLinux Kernel Introduction
Linux Kernel IntroductionSage Sharp
 
Breaking into Open Source and Linux: A USB 3.0 Success Story
Breaking into Open Source and Linux: A USB 3.0 Success StoryBreaking into Open Source and Linux: A USB 3.0 Success Story
Breaking into Open Source and Linux: A USB 3.0 Success StorySage Sharp
 
Vampire Mice: How USB PM Impacts You
Vampire Mice: How USB PM Impacts YouVampire Mice: How USB PM Impacts You
Vampire Mice: How USB PM Impacts YouSage Sharp
 

More from Sage Sharp (8)

Countering impostor syndrome culture
Countering impostor syndrome cultureCountering impostor syndrome culture
Countering impostor syndrome culture
 
Countering impostor syndrome culture
Countering impostor syndrome cultureCountering impostor syndrome culture
Countering impostor syndrome culture
 
Herding cats with django
Herding cats with djangoHerding cats with django
Herding cats with django
 
Open source 101 for students
Open source 101 for studentsOpen source 101 for students
Open source 101 for students
 
Small, smaller, smallest: A Tour of the Embedded World
Small, smaller, smallest: A Tour of the Embedded WorldSmall, smaller, smallest: A Tour of the Embedded World
Small, smaller, smallest: A Tour of the Embedded World
 
Linux Kernel Introduction
Linux Kernel IntroductionLinux Kernel Introduction
Linux Kernel Introduction
 
Breaking into Open Source and Linux: A USB 3.0 Success Story
Breaking into Open Source and Linux: A USB 3.0 Success StoryBreaking into Open Source and Linux: A USB 3.0 Success Story
Breaking into Open Source and Linux: A USB 3.0 Success Story
 
Vampire Mice: How USB PM Impacts You
Vampire Mice: How USB PM Impacts YouVampire Mice: How USB PM Impacts You
Vampire Mice: How USB PM Impacts You
 

Recently uploaded

Heltun_HE-RS01_User_Manual_B9AH.pdf
Heltun_HE-RS01_User_Manual_B9AH.pdfHeltun_HE-RS01_User_Manual_B9AH.pdf
Heltun_HE-RS01_User_Manual_B9AH.pdfMarielaL5
 
Zi-Stick UBS Dongle ZIgbee from Aeotec manual
Zi-Stick UBS Dongle ZIgbee from  Aeotec manualZi-Stick UBS Dongle ZIgbee from  Aeotec manual
Zi-Stick UBS Dongle ZIgbee from Aeotec manualDomotica daVinci
 
From eSIMs to iSIMs: It’s Inside the Manufacturing
From eSIMs to iSIMs: It’s Inside the ManufacturingFrom eSIMs to iSIMs: It’s Inside the Manufacturing
From eSIMs to iSIMs: It’s Inside the ManufacturingSoracom Global, Inc.
 
Manual Eurotronic Thermostatic Valve Comry Z-Wave
Manual Eurotronic Thermostatic Valve Comry Z-WaveManual Eurotronic Thermostatic Valve Comry Z-Wave
Manual Eurotronic Thermostatic Valve Comry Z-WaveDomotica daVinci
 
Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...
Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...
Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...Adrian Sanabria
 
2024 February Patch Tuesday
2024 February Patch Tuesday2024 February Patch Tuesday
2024 February Patch TuesdayIvanti
 
Navigating the Never Normal Strategies for Portfolio Leaders
Navigating the Never Normal Strategies for Portfolio LeadersNavigating the Never Normal Strategies for Portfolio Leaders
Navigating the Never Normal Strategies for Portfolio LeadersOnePlan Solutions
 
Microsoft Azure News - Feb 2024
Microsoft Azure News - Feb 2024Microsoft Azure News - Feb 2024
Microsoft Azure News - Feb 2024Daniel Toomey
 
Q1 Memory Fabric Forum: XConn CXL Switches for AI
Q1 Memory Fabric Forum: XConn CXL Switches for AIQ1 Memory Fabric Forum: XConn CXL Switches for AI
Q1 Memory Fabric Forum: XConn CXL Switches for AIMemory Fabric Forum
 
Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?
Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?
Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?GleecusTechlabs1
 
Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...
Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...
Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...Adrian Sanabria
 
Power of 2024 - WITforce Odyssey.pptx.pdf
Power of 2024 - WITforce Odyssey.pptx.pdfPower of 2024 - WITforce Odyssey.pptx.pdf
Power of 2024 - WITforce Odyssey.pptx.pdfkatalinjordans1
 
Bluetooth Low Energy(BLE) and beacons working
Bluetooth Low Energy(BLE) and beacons workingBluetooth Low Energy(BLE) and beacons working
Bluetooth Low Energy(BLE) and beacons workingshrey Ansh
 
Quinto Z-Wave Heltun_HE-RS01_User_Manual_B9AH.pdf
Quinto Z-Wave Heltun_HE-RS01_User_Manual_B9AH.pdfQuinto Z-Wave Heltun_HE-RS01_User_Manual_B9AH.pdf
Quinto Z-Wave Heltun_HE-RS01_User_Manual_B9AH.pdfDomotica daVinci
 
Evolution of Chatbots: From Custom AI Chatbots and AI Chatbots for Websites.pptx
Evolution of Chatbots: From Custom AI Chatbots and AI Chatbots for Websites.pptxEvolution of Chatbots: From Custom AI Chatbots and AI Chatbots for Websites.pptx
Evolution of Chatbots: From Custom AI Chatbots and AI Chatbots for Websites.pptxKyle Willson
 
Manual sensor Zigbee 3.0 MOES ZSS-X-PIRL-C
Manual  sensor Zigbee 3.0 MOES ZSS-X-PIRL-CManual  sensor Zigbee 3.0 MOES ZSS-X-PIRL-C
Manual sensor Zigbee 3.0 MOES ZSS-X-PIRL-CDomotica daVinci
 
Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...
Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...
Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...Memory Fabric Forum
 
Journey of Television in World & in India
Journey of Television in World & in IndiaJourney of Television in World & in India
Journey of Television in World & in IndiaAdarshAgarwal66
 
Importance of magazines in education ppt
Importance of magazines in education pptImportance of magazines in education ppt
Importance of magazines in education pptsafnarafeek2002
 

Recently uploaded (20)

Heltun_HE-RS01_User_Manual_B9AH.pdf
Heltun_HE-RS01_User_Manual_B9AH.pdfHeltun_HE-RS01_User_Manual_B9AH.pdf
Heltun_HE-RS01_User_Manual_B9AH.pdf
 
Zi-Stick UBS Dongle ZIgbee from Aeotec manual
Zi-Stick UBS Dongle ZIgbee from  Aeotec manualZi-Stick UBS Dongle ZIgbee from  Aeotec manual
Zi-Stick UBS Dongle ZIgbee from Aeotec manual
 
From eSIMs to iSIMs: It’s Inside the Manufacturing
From eSIMs to iSIMs: It’s Inside the ManufacturingFrom eSIMs to iSIMs: It’s Inside the Manufacturing
From eSIMs to iSIMs: It’s Inside the Manufacturing
 
Manual Eurotronic Thermostatic Valve Comry Z-Wave
Manual Eurotronic Thermostatic Valve Comry Z-WaveManual Eurotronic Thermostatic Valve Comry Z-Wave
Manual Eurotronic Thermostatic Valve Comry Z-Wave
 
Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...
Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...
Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...
 
2024 February Patch Tuesday
2024 February Patch Tuesday2024 February Patch Tuesday
2024 February Patch Tuesday
 
Navigating the Never Normal Strategies for Portfolio Leaders
Navigating the Never Normal Strategies for Portfolio LeadersNavigating the Never Normal Strategies for Portfolio Leaders
Navigating the Never Normal Strategies for Portfolio Leaders
 
Microsoft Azure News - Feb 2024
Microsoft Azure News - Feb 2024Microsoft Azure News - Feb 2024
Microsoft Azure News - Feb 2024
 
Q1 Memory Fabric Forum: XConn CXL Switches for AI
Q1 Memory Fabric Forum: XConn CXL Switches for AIQ1 Memory Fabric Forum: XConn CXL Switches for AI
Q1 Memory Fabric Forum: XConn CXL Switches for AI
 
Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?
Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?
Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?
 
Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...
Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...
Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...
 
Power of 2024 - WITforce Odyssey.pptx.pdf
Power of 2024 - WITforce Odyssey.pptx.pdfPower of 2024 - WITforce Odyssey.pptx.pdf
Power of 2024 - WITforce Odyssey.pptx.pdf
 
Bluetooth Low Energy(BLE) and beacons working
Bluetooth Low Energy(BLE) and beacons workingBluetooth Low Energy(BLE) and beacons working
Bluetooth Low Energy(BLE) and beacons working
 
5 Tech Trend to Notice in ESG Landscape- 47Billion
5 Tech Trend to Notice in ESG Landscape- 47Billion5 Tech Trend to Notice in ESG Landscape- 47Billion
5 Tech Trend to Notice in ESG Landscape- 47Billion
 
Quinto Z-Wave Heltun_HE-RS01_User_Manual_B9AH.pdf
Quinto Z-Wave Heltun_HE-RS01_User_Manual_B9AH.pdfQuinto Z-Wave Heltun_HE-RS01_User_Manual_B9AH.pdf
Quinto Z-Wave Heltun_HE-RS01_User_Manual_B9AH.pdf
 
Evolution of Chatbots: From Custom AI Chatbots and AI Chatbots for Websites.pptx
Evolution of Chatbots: From Custom AI Chatbots and AI Chatbots for Websites.pptxEvolution of Chatbots: From Custom AI Chatbots and AI Chatbots for Websites.pptx
Evolution of Chatbots: From Custom AI Chatbots and AI Chatbots for Websites.pptx
 
Manual sensor Zigbee 3.0 MOES ZSS-X-PIRL-C
Manual  sensor Zigbee 3.0 MOES ZSS-X-PIRL-CManual  sensor Zigbee 3.0 MOES ZSS-X-PIRL-C
Manual sensor Zigbee 3.0 MOES ZSS-X-PIRL-C
 
Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...
Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...
Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...
 
Journey of Television in World & in India
Journey of Television in World & in IndiaJourney of Television in World & in India
Journey of Television in World & in India
 
Importance of magazines in education ppt
Importance of magazines in education pptImportance of magazines in education ppt
Importance of magazines in education ppt
 

Advanced Git Tutorial

  • 1. Advanced Git Tutorial by Sarah Sharp
  • 2. WARNING: I am a unique snowflake
  • 4. WARNING: Some Git features are dangerous!
  • 5. What is Git? ● Distributed ● Fast ● Flexible
  • 6. Git Basics ● See Everyday Git Tutorial: – http://www.kernel.org/pub/software/scm/git/doc s/everyday.html ● My git commands: – git add - git commit – git diff - git log - git show – git push - git pull – git fetch - git rebase
  • 7. Naming commits <Commitish> ● (Indirect) hash of repo files, current commit message, and ancestor commits. ● HEAD refers to the last commit ● ~ at the end means commit before that – e.g. HEAD~ – ^ is roughly equivalent to ~ ● A branch points to a specific commit ● see git rev-parse
  • 9. Git Philosophy ● Commit early, commit often ● One commit represents one idea or one change. – Makes it easy to read patches – Easy to revert unwanted changes later ● Your working directory, index, and local repo are your scratch pads.
  • 10. Frequent Use Infrequent Use
  • 11. The Index, the staging area Front stage: Back stage: Changes to be committed Uncommited changes and unadded files
  • 12. Staging Changes ● git add <file> – adds a file to the Index ● git commit – commits added changes to the local repo ● But what about files not added to the Index?
  • 13. Staging Changes ● git add <file> – adds a file to the Index ● git commit – commits added changes to the local repo ● But what about files not added to the Index? – Answer: they aren't included in the commit. ● Key idea: You can add and commit files separately from other files. – This makes separating changes into small patches easier.
  • 14. What changed? ● git status ● git diff git diff HEAD local workspace repository git diff index git diff --cached
  • 16. Advanced Staging ● git add --patch – try the "split" option to split across hunks ● git add -i – Very powerful tool with lots of options ● Key idea: You can add and commit different parts of a file separately.
  • 17. Unstaging changes ● Revert to the last commit – git reset --hard HEAD ● Remove all added changes from the index – git reset --mixed HEAD ● Remove some files added to index – git add -i and choose revert, or – git reset HEAD filename(s)
  • 19. Viewing History ● git log ● git log <commit A>..<commit B> – shows history after commit A, up to commit B – can omit either commit – e.g. `git log` `git log origin..` `git log ..v2.6.30` ● git log -p – shows log as a series of patches ● git log --pretty=oneline –abbrev-commit
  • 21. Viewing old files ● Contents of a file at a particular commit – git show <commitish>:<path to file> ● Contents of a directory – git show <commitish>:<directory>
  • 22. Pointing Fingers: git blame
  • 23. Pointing Fingers ● git blame <file> – show who committed each line ● git blame <commit ID> <file> – show the line history before that commit
  • 25. Branches ● Only one branch can be checked out – trunk ~= master ● show all branches – git branch -a ● switching branches – git checkout name ● creating new branches – git checkout -b name <commit>
  • 26. Advanced Branching ● Merge branches with git merge – creates a "merge commit" ● Rebase current branch against branch B – find a common ancestor commit – apply commits from branch B – apply commits from current branch ● Apply a commit from one branch – git cherry-pick
  • 28. Interacting with other people ● Creating a patchset, starting at commitA – git format-patch -o directory commitA^ --cc=<cced-email> – use git send-email or `mutt -H <gitpatch>` ● Applying a patch – git am patchfile – can also take a mailbox or maildir or stdin ● Pushing a new branch – git push remote branch
  • 30. Changing History: DANGER, WILL ROBINSON! ● After a commit, often you will find bugs – could make a new bug fix commit – or you could "amend" the previous commit ● Fix your code ● git add <file> – This adds your code to the index ● git commit --amend – This modifies the commit in the local repo – useful to have vim git-commit script installed
  • 31. Changing History: DANGER, WILL ROBINSON! ● A total history rewrite: – git rebase -i <commit ID> ● Can reorder commits ● Can edit commits ● Can "squash" one commit into another ● May have merge conflicts – edit files, resolve conflicts surrounded by <<<< and >>>> – git add files, git rebase --continue
  • 32. git rebase -i --dontscrewme ● No such command ● git rebase -i the safe way: – git checkout -b master-rebase – use `git rebase -i` to move one patch – resolve any merge conflicts – squash that patch using `git rebase -i` – git diff master master-rebase – git branch -M master master-old – git branch -M master-rebase master
  • 34. Git Hooks ● Hooks are scripts found in .git/hooks/ ● Enable them with chmod a+x <file> ● Triggered by various git commands – e.g. git commit, git push – pre-commit, post-update ● Examples – shipped pre-commit hook checks for white space at the end of line, long lines, etc. – Checking for swear words?
  • 35. Git Hooks ● Example post-update hook on remote repo: #!/bin/sh cd /home/sarah/blog unset GIT_DIR git-fetch origin git-reset --hard origin/master ● Whenever I push to the remote repository, this goes into the server's checkout of my blog git repo and updates it unconditionally.
  • 36. Setting up a remote repository
  • 37. Setting up a remote repository ● Server needs git and sshd installed to use git+ssh to push to your repo ● Server needs webDAV installed to allow push to your repo over https ● http://github.com/ will host your repo ● Next directions assume you have your own server with git installed
  • 38. Setting up a remote repository 1. Make local repo, commit stuff, etc. 2. ssh to the server: GIT_DIR=/path/to/repo git init --shared 3. Next, tell the local repo about the server: git remote add origin git+ssh://hostname/path/to/repo 4. Push to the server from the local repo: git push origin master 5. Clean up the local repo so that you can pull from the remote server: git config branch.master.remote origin git config branch.master.merge refs/heads/master
  • 39. Resources ● Git work flow diagrams: http://osteele.com/archives/2008/05/my-git-workflow ● The Tangled Working Copy: http://tomayko.com/writings/the-thing-about-git ● http://github.com/ ● Kernel module examples at http://lwn.net/Kernel/LDD3/ ● vim git-commit script will display commit messages in a more useful manner. Script kept at vim.sourceforge.net. – sudo aptitude install vim-scripts vim-addon-manager – vim-addons install git-commit
  • 40. Creative Commons Image Attributions ● GIT picture: http://flickr.com/photos/29862082@N06/2908889599/ ● Snowflake: http://commons.wikimedia.org/wiki/Image:SnowflakesWilson Bentley.jpg ● Danger:http://flickr.com/photos/dawvon/32305882/ ● Cat: http://flickr.com/photos/jamilsoni/118499378/ ● Remote: http://flickr.com/photos/markkelley/957631507/ ● Philosophy: http://flickr.com/photos/paullew/2442045767/ ● Branches: http://flickr.com/photos/shapeshift/136184752/ ● Interacting with other people: http://www.flickr.com/photos/exlibris/3222440467/
  • 41. Creative Commons Image Attributions ● Front stage: http://flickr.com/photos/69108241@N00/118040089/ ● Back stage: http://flickr.com/photos/piotramigo/2561391320/ ● Hooks:http://www.flickr.com/photos/yabanji/3175297773/ ● Blame: http://flickr.com/photos/iandesign/1205496024/ ● Ballet: http://www.flickr.com/photos/oudeschool/3553416511/ ● Papyrus: http://flickr.com/photos/charlestilford/2548991271/
  • 42. Thank you! ● Sarah Sharp ● @sarahsharp ● http://sarah.thesharps.us