SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
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
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
Git Philosophy
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.
Frequent Use   Infrequent Use
The Index, the staging area




      Front stage:             Back stage:
 Changes to be committed   Uncommited changes
                            and unadded files
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?
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.
What changed?
 ●   git status
 ●   git diff


                        git diff HEAD
                                                       local
workspace
                                                    repository
            git diff   index    git diff --cached
Advanced Staging
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.
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)
Viewing History
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
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>
Pointing Fingers:
   git blame
Pointing Fingers
●   git blame <file>
    –   show who committed each line
●   git blame <commit ID> <file>
    –   show the line history before that commit
Branches
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>
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
Interacting with other people
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
Changing History
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
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
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
Git Hooks
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?
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.
Setting up a
remote repository
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
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
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
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/
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/
Thank you!
●   Sarah Sharp
●   @sarahsharp
●   http://sarah.thesharps.us

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
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
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
 
Git Terminologies
Git TerminologiesGit Terminologies
Git Terminologies
 
Git l'essentiel
Git l'essentielGit l'essentiel
Git l'essentiel
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
 
Git basics
Git basicsGit basics
Git basics
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Git Introduction
Git IntroductionGit Introduction
Git Introduction
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
git and github
git and githubgit and github
git and github
 
Tutorial Git
Tutorial GitTutorial Git
Tutorial Git
 
Git Grundlagen
Git GrundlagenGit Grundlagen
Git Grundlagen
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 

Destacado

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
 

Destacado (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 a 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 a 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
 

Más de 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
 

Más de 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
 

Último

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 

Último (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 

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
  • 20.
  • 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