SlideShare ist ein Scribd-Unternehmen logo
1 von 42
git more done
Kwen Peterson
Senior Software Developer @ Raven
kwen.peterson@gmail.com
@kwenarik
"You're already in the top tier of developers just
by showing up here tonight. I don't know how
talented you are, how much experience you have,
but you showed up. You're putting yourself out
there because you care to improve. Thanks for
caring.“ – Scott Hanselman
Distributed
• One of the coolest features of any of the
Distributed VCSs, Git included, is that it isn‟t
centralized.
– This means that even if you're using a centralized
workflow, every user has what is essentially a full
backup of the main server, each of which could be
pushed up to replace the main server in the event of a
crash or corruption.
– There is basically no single point of failure with a
distributed VCS.
Git is Fast
• Git is extremely fast. Since all operations (except
for push and fetch) are local there is no network
latency involved to:
–
–
–
–
–

Perform a diff.
View file history.
Commit changes.
Merge branches.
Obtain any other revision of a file (not just the prior
committed revision).
– Switch branches.
Git is orders of
magnitude faster than SVN.
Operation

Git

SVN

Speed

Commit Files (A)

0.64

2.60

4x

Commit Images
(B)

1.53

24.70

16x

Diff Current

0.25

1.09

4x

Diff Recent

0.25

3.99

16x

Diff Tags

1.17

83.57

71x

Log (50)

0.01

0.38

31x

Log (All)

0.52

169.20

325x

Log (File)

0.60

82.84

138x

Update

0.90

2.82

3x

Blame

1.91

3.04

1x
Git is Small
• Git's repository and working directory sizes are extremely small
when compared to SVN.
– The Mozilla repository is reported to be almost 12 Gb stored across 240,000 files
in SVN.
– The exact same history is stored in Git using two files totaling just over 420 Mb.

• This means that SVN requires 30x the disk space to store the same
history!
– One of the reasons for the smaller repo size is that an SVN working directory
always contains two copies of each file: one for the user to actually work with and
another hidden in .svn/ to aid operations such as status, diff and commit.
– In contrast a Git working directory requires only one small index file that stores
about 100 bytes of data per tracked file. On projects with a large number of files
this can be a substantial difference in the disk space required per working copy.
Git is *
• GitHub
– 3 million+ users
– 5 million+ repositories
– THE place for open-source projects

• Merging & Branching are easy
– (unlike in many centralized systems)
The branch Dilemma
I have a 120 hour work package to do!
SVN:
– sit on 3 weeks worth of changes unversioned and then finally push 1
massive commit?
– push updates to trunk/branch as necessary and possibly break
functionality for anyone else working on project (but get to keep commit
history, and not have 1 massive commit)

Git:
– make daily commits to my local branch (full history, able to rollback to
intermediate stages!)
– merge in changes that others have pushed to the master branch at my
convenience
– hold off pushing to master until my code is fully polished and tested out,
minimizing impact on other developers
Code Reviews
• SVN
– Make a patch of uncommitted changes and send it
to another developer, and hope that they have an
SVN branch at the exact commit as yours to apply it
to.

•

Git
–

Push a copy of your local branch (and all its
commits) out to a remote branch on a repository,
where anyone can easily pull down a copy and build
your code, no matter where there current branch is.
git-svn
• “Git is the best SVN client out there.” – Keith
Dahlby
• Gives you ALL the local repository benefits of
git, while letting you treat your SVN repo as „just
another remote‟
Subversion-Style Workflow
Integration Manager Workflow
Dictator & Lieutenants Workflow
Felix Baumgartner – Red Bull
Creating a Repository
• git init
– Creates an empty repository at current location

• git clone <url>
– Creates a local copy of an existing repository
– Examples:
• git clone http://github.com/jquery/jquery.git
Working with Remotes
• git remote add <name> <url>
– Maps a remote
– Example:
git remote kwen git://source/kwen-test.git

• git remote show <name>
– Displays a list of branches on the remote, any local
branches that track them, fetch URL, etc.

• git remote rm <name>
• git remote rename <old> <new>
Working with Branches
• git checkout <branch>
– Change to the specified local branch

• git branch <name> <remote>/<branch>
– Create a local branch that tracks the remote branch
– Example: git branch milestone3 kwen-test/milestone3

• git checkout –b <name> <remote>/<branch>
– Creates a new local branch and immediately checks it out
– Example: git co –b codereview kwen-test/milestone4
Dealing with Changes
• git st
– Shows you the status of currently modified files (tracked &
untracked)

• git add <file> (use a gui instead!)
– adds the specified file to the list of tracked changes

• git commit –m <message> (use a gui instead!)
– Commits all tracked changes to the current branch

• git reset HEAD –hard
– Reset current branch and lose ALL changes

• git stash <tag>
– Store all current changes away temporarily
– The tag is optional, and it will generate one for you if not provided

• git stash apply <tag>
– Reapply the last set of stashed changes onto
the current branch
Pushing and Pulling Changes
• git fetch <name>
– Gets the latest updates from the remote, but does NOT apply them
– Example: git fetch origin

• git pull <remote> <branch>
– Runs git fetch and then git merge
– If you are on a branch that already tracks a remote, you can just use git
pull, and it will merge any updates in the tracked remote branch into your
local branch.
– Can pass a --rebase parameter to rebase instead of merge

• git push <remote> <name>:<branch>
– Pushes the updates in my current local branch out to a remote branch
– Example: git push origin milestone3:milestone3
Git Trivia
1. Git push origin master:master
2. Git push origin +master:master

3. Git push origin –f master:master
Creating & Applying Patches
• git format-patch <branch>
– Creates patches for the diff between the current branch & <branch>
– Example: My local dev branch has updates that have not been
committed to origin/dev yet, but that I need to send to Wes.
Running git format-patch origin/dev creates patches for each of the
commits that are on my local dev branch that are not in origin/dev.

• git format-patch -#
– Same as above, except this method simply takes the last X
commits and creates patches for them.
– Example: git format-patch -3 (creates patches for the last 3 commits
you made on this branch)

• git am -3 –s –i <file or folder>
– Apply the specified patches to the current branch
– Example: git am -3 –s –i patches/* (applies all the patches located
in my patches folder)
Copy/Paste a commit locally
• Git cherry-pick <hash>
– Copies the changeset for the given commit onto the
current branch
– (Great way to apply a hotfix to multiple different
branches.)

*
Bug, or…

https://twitter.com/pardel/status/372750244963819522/photo/1
https://twitter.com/GeorgeTakei/status/385913390377750528/photo/1
Common git branching strategy
• 3 core branches: master, dev, release
– Master is “the truth” and should always be in a stable,
fully-functional state. This is where new topic/feature
branches are cloned from. (nightly builds)
– Dev is where integration testing happens. This is
where topic branches are pushed and tested PRIOR
to being signed off on as stable enough to go to
master. (continuous integration, test environment)
– Release is where the last live build lives. This exists
so that if an absolutely critical issue arises, we can
make the fix here and release the build, being
confident that the ONLY change going out is the
critical bug fix.
Awesomest. Baby Bib. Ever.
Rebase vs. Merge (1)
• Merging brings two lines of development
together while preserving the ancestry of each
commit history.
• In contrast, rebasing unifies the lines of
development by re-writing changes from the
source branch so that they appear as children of
the destination branch – effectively pretending
that those commits were written on top of the
destination branch all along.
Play Doh
Rebase vs. Merge (2)
• Rebase requires the commits on the source
branch to be re-written, which changes their
content and their SHAS.
• Merging is better if you only have one (or few
trusted) commiter(s) and you don‟t care much
about reading your history.
• Rebasing makes you sure that your commits go
on top of the „public‟ branch.

31
Commit graph (merge)
Commit graph (rebase)
Rebase vs. Merge (3)
• git merge <branch>
– Merge changes in the specified branch onto the current branch
– If you run into merge conflicts, the current branch is called local, and the
branch you are merging in is referred to as remote.

• git rebase <remote>/<branch>
– Base the current branch you are on off the specified remote branch
– Takes the specified branch as the base, and then applies any changes
you have in your local branch on top of that. For conflicts, the current
branch is called remote, and the branch you are rebasing off of is treated
as local.
– Example: git rebase origin/master
Merge
• Pros
– Simple to use and understand
– The commits on the source branch remain separate from
other branch commits, provided you don‟t perform a fastforward merge. (This separation can be useful in the case
of feature branches, where you might want to take a
feature and merge it into another branch later.)
– Existing commits on the source branch are unchanged and
remain valid; it doesn‟t matter if they‟ve been shared.
• Cons
– If the need to merge arises simply because multiple people
are working on the same branch in parallel, the merges
don‟t serve any useful historical purpose & create clutter.
Rebase
• Pros
– Simplifies your history.
– Is the most intuitive and clutter-free way to combine
commits from multiple developers in a shared branch.

• Cons
– Slightly more complex, conflicts require resolution on
a per commit basis.
– Rewriting of history has ramifications if you‟ve
previously pushed those commits elsewhere.
Golden Rule of Rebasing

• NEVER EVER rebase a branch
that you pushed, or that you
pulled from another person.

37
Interactive Rebase (Squash)
• git rebase –i HEAD~3
– pick f392171 Added new feature X
– pick ba9dd9a Added new elements to page design
– pick df71a27 Updated CSS for new elements

• Change to:
– pick f392171 Added new feature X
– squash ba9dd9a Added new elements to page
design
– squash df71a27 Updated CSS for new elements
Reflog, Detached Heads, Submodules
• Git reflog – „restore points‟ for everything you do!
• Git reset –hard <hash>
• Detached Head – Tracking a specific commit,
not a branch!
• Submodules – Shared „child‟ git repository
(notorious for detached HEAD issues…)
Resources
• Recommended
– http://rogerdudler.github.io/git-guide/
– http://www.slideshare.net/lemiorhan/git-branchingmodel?utm_source=slideshow&utm_medium=ssemail&utm_campaign=wee
kly_digest

• Comparison vs. SVN
–
–
–
–

http://whygitisbetterthanx.com/
http://git-scm.com/course/svn.html
https://git.wiki.kernel.org/index.php/GitSvnComparison
http://zurb.com/article/597/the-one-critical-reason-we-switched-from-

• Git Clients
– https://code.google.com/p/gitextensions/
– http://sourcetreeapp.com/
– https://github.com/dahlbyk/posh-git
Kwen Peterson
• http://tinyurl.com/rsdcc13
– https://github.com/Kwen/sdcc2013
– http://speakerrate.com/talks/27811-git-more-done
– http://www.slideshare.net/KwenPeterson/git-moredone

•
•
•
•

@kwenarik
#sdcc2013
plus.google.com/+KwenPeterson
kwen.peterson@gmail.com
https://github.com/Kwen

Weitere ähnliche Inhalte

Was ist angesagt?

Version control
Version controlVersion control
Version controlvisual28
 
An introduction to Git
An introduction to GitAn introduction to Git
An introduction to GitMuhil Vannan
 
Git learning
Git learningGit learning
Git learningAmit Gupta
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction TutorialThomas Rausch
 
Subversion to Git Migration
Subversion to Git MigrationSubversion to Git Migration
Subversion to Git MigrationTim Massey
 
From svn to git
From svn to gitFrom svn to git
From svn to gitNehal Shah
 
Git hub ppt presentation
Git hub ppt presentationGit hub ppt presentation
Git hub ppt presentationAyanaRukasar
 
Git-ing out of your git messes - Fluent Conf 2017
Git-ing out of  your git messes - Fluent Conf 2017Git-ing out of  your git messes - Fluent Conf 2017
Git-ing out of your git messes - Fluent Conf 2017Katie Sylor-Miller
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to gitRandal Schwartz
 
Git tutorial II
Git tutorial IIGit tutorial II
Git tutorial IIJim Yeh
 
GIT presentation
GIT presentationGIT presentation
GIT presentationNaim Latifi
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To GitArnaud Seilles
 
Source Code Management systems
Source Code Management systemsSource Code Management systems
Source Code Management systemsxSawyer
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Git from SVN
Git from SVNGit from SVN
Git from SVNJustin Yoo
 

Was ist angesagt? (20)

Version control
Version controlVersion control
Version control
 
An introduction to Git
An introduction to GitAn introduction to Git
An introduction to Git
 
Git learning
Git learningGit learning
Git learning
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
 
Subversion to Git Migration
Subversion to Git MigrationSubversion to Git Migration
Subversion to Git Migration
 
From svn to git
From svn to gitFrom svn to git
From svn to git
 
Git hub ppt presentation
Git hub ppt presentationGit hub ppt presentation
Git hub ppt presentation
 
Git-ing out of your git messes - Fluent Conf 2017
Git-ing out of  your git messes - Fluent Conf 2017Git-ing out of  your git messes - Fluent Conf 2017
Git-ing out of your git messes - Fluent Conf 2017
 
Git basics
Git basicsGit basics
Git basics
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Git tutorial II
Git tutorial IIGit tutorial II
Git tutorial II
 
Git training
Git trainingGit training
Git training
 
GIT presentation
GIT presentationGIT presentation
GIT presentation
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
Source Code Management systems
Source Code Management systemsSource Code Management systems
Source Code Management systems
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Git from SVN
Git from SVNGit from SVN
Git from SVN
 

Ă„hnlich wie Git more done

Git 101
Git 101Git 101
Git 101jayrparro
 
MakingGitWorkForYou
MakingGitWorkForYouMakingGitWorkForYou
MakingGitWorkForYouKwen Peterson
 
GIT In Detail
GIT In DetailGIT In Detail
GIT In DetailHaitham Raik
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Ahmed El-Arabawy
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github Max Claus Nunes
 
GIT_training_SoftServeBulgaria2016
GIT_training_SoftServeBulgaria2016GIT_training_SoftServeBulgaria2016
GIT_training_SoftServeBulgaria2016Peter Denev
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developersAidan Casey
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitRobert Lee-Cann
 
Source Code Management with Git
Source Code Management with GitSource Code Management with Git
Source Code Management with GitThings Lab
 
Git cheat sheet__grey
Git cheat sheet__greyGit cheat sheet__grey
Git cheat sheet__greyKing Hom
 
Git cheat sheet__white
Git cheat sheet__whiteGit cheat sheet__white
Git cheat sheet__whiteKing Hom
 
Git cheat sheet_dark
Git cheat sheet_darkGit cheat sheet_dark
Git cheat sheet_darkKing Hom
 
Git workflows automat-it
Git workflows automat-itGit workflows automat-it
Git workflows automat-itAutomat-IT
 

Ă„hnlich wie Git more done (20)

git.ppt.pdf
git.ppt.pdfgit.ppt.pdf
git.ppt.pdf
 
Git 101
Git 101Git 101
Git 101
 
GIT.pptx
GIT.pptxGIT.pptx
GIT.pptx
 
MakingGitWorkForYou
MakingGitWorkForYouMakingGitWorkForYou
MakingGitWorkForYou
 
Git
GitGit
Git
 
GIT In Detail
GIT In DetailGIT In Detail
GIT In Detail
 
git Technologies
git Technologiesgit Technologies
git Technologies
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
GIT_training_SoftServeBulgaria2016
GIT_training_SoftServeBulgaria2016GIT_training_SoftServeBulgaria2016
GIT_training_SoftServeBulgaria2016
 
SVN 2 Git
SVN 2 GitSVN 2 Git
SVN 2 Git
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developers
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 
Source Code Management with Git
Source Code Management with GitSource Code Management with Git
Source Code Management with Git
 
Git cheat sheet__grey
Git cheat sheet__greyGit cheat sheet__grey
Git cheat sheet__grey
 
Git cheat sheet__white
Git cheat sheet__whiteGit cheat sheet__white
Git cheat sheet__white
 
Git cheat sheet_dark
Git cheat sheet_darkGit cheat sheet_dark
Git cheat sheet_dark
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Git 101
Git 101Git 101
Git 101
 
Git workflows automat-it
Git workflows automat-itGit workflows automat-it
Git workflows automat-it
 

KĂĽrzlich hochgeladen

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂşjo
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

KĂĽrzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Git more done

  • 1. git more done Kwen Peterson Senior Software Developer @ Raven kwen.peterson@gmail.com @kwenarik
  • 2. "You're already in the top tier of developers just by showing up here tonight. I don't know how talented you are, how much experience you have, but you showed up. You're putting yourself out there because you care to improve. Thanks for caring.“ – Scott Hanselman
  • 3. Distributed • One of the coolest features of any of the Distributed VCSs, Git included, is that it isn‟t centralized. – This means that even if you're using a centralized workflow, every user has what is essentially a full backup of the main server, each of which could be pushed up to replace the main server in the event of a crash or corruption. – There is basically no single point of failure with a distributed VCS.
  • 4. Git is Fast • Git is extremely fast. Since all operations (except for push and fetch) are local there is no network latency involved to: – – – – – Perform a diff. View file history. Commit changes. Merge branches. Obtain any other revision of a file (not just the prior committed revision). – Switch branches.
  • 5. Git is orders of magnitude faster than SVN. Operation Git SVN Speed Commit Files (A) 0.64 2.60 4x Commit Images (B) 1.53 24.70 16x Diff Current 0.25 1.09 4x Diff Recent 0.25 3.99 16x Diff Tags 1.17 83.57 71x Log (50) 0.01 0.38 31x Log (All) 0.52 169.20 325x Log (File) 0.60 82.84 138x Update 0.90 2.82 3x Blame 1.91 3.04 1x
  • 6. Git is Small • Git's repository and working directory sizes are extremely small when compared to SVN. – The Mozilla repository is reported to be almost 12 Gb stored across 240,000 files in SVN. – The exact same history is stored in Git using two files totaling just over 420 Mb. • This means that SVN requires 30x the disk space to store the same history! – One of the reasons for the smaller repo size is that an SVN working directory always contains two copies of each file: one for the user to actually work with and another hidden in .svn/ to aid operations such as status, diff and commit. – In contrast a Git working directory requires only one small index file that stores about 100 bytes of data per tracked file. On projects with a large number of files this can be a substantial difference in the disk space required per working copy.
  • 7. Git is * • GitHub – 3 million+ users – 5 million+ repositories – THE place for open-source projects • Merging & Branching are easy – (unlike in many centralized systems)
  • 8. The branch Dilemma I have a 120 hour work package to do! SVN: – sit on 3 weeks worth of changes unversioned and then finally push 1 massive commit? – push updates to trunk/branch as necessary and possibly break functionality for anyone else working on project (but get to keep commit history, and not have 1 massive commit) Git: – make daily commits to my local branch (full history, able to rollback to intermediate stages!) – merge in changes that others have pushed to the master branch at my convenience – hold off pushing to master until my code is fully polished and tested out, minimizing impact on other developers
  • 9. Code Reviews • SVN – Make a patch of uncommitted changes and send it to another developer, and hope that they have an SVN branch at the exact commit as yours to apply it to. • Git – Push a copy of your local branch (and all its commits) out to a remote branch on a repository, where anyone can easily pull down a copy and build your code, no matter where there current branch is.
  • 10. git-svn • “Git is the best SVN client out there.” – Keith Dahlby • Gives you ALL the local repository benefits of git, while letting you treat your SVN repo as „just another remote‟
  • 15. Creating a Repository • git init – Creates an empty repository at current location • git clone <url> – Creates a local copy of an existing repository – Examples: • git clone http://github.com/jquery/jquery.git
  • 16. Working with Remotes • git remote add <name> <url> – Maps a remote – Example: git remote kwen git://source/kwen-test.git • git remote show <name> – Displays a list of branches on the remote, any local branches that track them, fetch URL, etc. • git remote rm <name> • git remote rename <old> <new>
  • 17. Working with Branches • git checkout <branch> – Change to the specified local branch • git branch <name> <remote>/<branch> – Create a local branch that tracks the remote branch – Example: git branch milestone3 kwen-test/milestone3 • git checkout –b <name> <remote>/<branch> – Creates a new local branch and immediately checks it out – Example: git co –b codereview kwen-test/milestone4
  • 18. Dealing with Changes • git st – Shows you the status of currently modified files (tracked & untracked) • git add <file> (use a gui instead!) – adds the specified file to the list of tracked changes • git commit –m <message> (use a gui instead!) – Commits all tracked changes to the current branch • git reset HEAD –hard – Reset current branch and lose ALL changes • git stash <tag> – Store all current changes away temporarily – The tag is optional, and it will generate one for you if not provided • git stash apply <tag> – Reapply the last set of stashed changes onto the current branch
  • 19. Pushing and Pulling Changes • git fetch <name> – Gets the latest updates from the remote, but does NOT apply them – Example: git fetch origin • git pull <remote> <branch> – Runs git fetch and then git merge – If you are on a branch that already tracks a remote, you can just use git pull, and it will merge any updates in the tracked remote branch into your local branch. – Can pass a --rebase parameter to rebase instead of merge • git push <remote> <name>:<branch> – Pushes the updates in my current local branch out to a remote branch – Example: git push origin milestone3:milestone3
  • 20. Git Trivia 1. Git push origin master:master 2. Git push origin +master:master 3. Git push origin –f master:master
  • 21. Creating & Applying Patches • git format-patch <branch> – Creates patches for the diff between the current branch & <branch> – Example: My local dev branch has updates that have not been committed to origin/dev yet, but that I need to send to Wes. Running git format-patch origin/dev creates patches for each of the commits that are on my local dev branch that are not in origin/dev. • git format-patch -# – Same as above, except this method simply takes the last X commits and creates patches for them. – Example: git format-patch -3 (creates patches for the last 3 commits you made on this branch) • git am -3 –s –i <file or folder> – Apply the specified patches to the current branch – Example: git am -3 –s –i patches/* (applies all the patches located in my patches folder)
  • 22. Copy/Paste a commit locally • Git cherry-pick <hash> – Copies the changeset for the given commit onto the current branch – (Great way to apply a hotfix to multiple different branches.) *
  • 25. Common git branching strategy • 3 core branches: master, dev, release – Master is “the truth” and should always be in a stable, fully-functional state. This is where new topic/feature branches are cloned from. (nightly builds) – Dev is where integration testing happens. This is where topic branches are pushed and tested PRIOR to being signed off on as stable enough to go to master. (continuous integration, test environment) – Release is where the last live build lives. This exists so that if an absolutely critical issue arises, we can make the fix here and release the build, being confident that the ONLY change going out is the critical bug fix.
  • 26.
  • 27.
  • 29. Rebase vs. Merge (1) • Merging brings two lines of development together while preserving the ancestry of each commit history. • In contrast, rebasing unifies the lines of development by re-writing changes from the source branch so that they appear as children of the destination branch – effectively pretending that those commits were written on top of the destination branch all along.
  • 31. Rebase vs. Merge (2) • Rebase requires the commits on the source branch to be re-written, which changes their content and their SHAS. • Merging is better if you only have one (or few trusted) commiter(s) and you don‟t care much about reading your history. • Rebasing makes you sure that your commits go on top of the „public‟ branch. 31
  • 34. Rebase vs. Merge (3) • git merge <branch> – Merge changes in the specified branch onto the current branch – If you run into merge conflicts, the current branch is called local, and the branch you are merging in is referred to as remote. • git rebase <remote>/<branch> – Base the current branch you are on off the specified remote branch – Takes the specified branch as the base, and then applies any changes you have in your local branch on top of that. For conflicts, the current branch is called remote, and the branch you are rebasing off of is treated as local. – Example: git rebase origin/master
  • 35. Merge • Pros – Simple to use and understand – The commits on the source branch remain separate from other branch commits, provided you don‟t perform a fastforward merge. (This separation can be useful in the case of feature branches, where you might want to take a feature and merge it into another branch later.) – Existing commits on the source branch are unchanged and remain valid; it doesn‟t matter if they‟ve been shared. • Cons – If the need to merge arises simply because multiple people are working on the same branch in parallel, the merges don‟t serve any useful historical purpose & create clutter.
  • 36. Rebase • Pros – Simplifies your history. – Is the most intuitive and clutter-free way to combine commits from multiple developers in a shared branch. • Cons – Slightly more complex, conflicts require resolution on a per commit basis. – Rewriting of history has ramifications if you‟ve previously pushed those commits elsewhere.
  • 37. Golden Rule of Rebasing • NEVER EVER rebase a branch that you pushed, or that you pulled from another person. 37
  • 38.
  • 39. Interactive Rebase (Squash) • git rebase –i HEAD~3 – pick f392171 Added new feature X – pick ba9dd9a Added new elements to page design – pick df71a27 Updated CSS for new elements • Change to: – pick f392171 Added new feature X – squash ba9dd9a Added new elements to page design – squash df71a27 Updated CSS for new elements
  • 40. Reflog, Detached Heads, Submodules • Git reflog – „restore points‟ for everything you do! • Git reset –hard <hash> • Detached Head – Tracking a specific commit, not a branch! • Submodules – Shared „child‟ git repository (notorious for detached HEAD issues…)
  • 41. Resources • Recommended – http://rogerdudler.github.io/git-guide/ – http://www.slideshare.net/lemiorhan/git-branchingmodel?utm_source=slideshow&utm_medium=ssemail&utm_campaign=wee kly_digest • Comparison vs. SVN – – – – http://whygitisbetterthanx.com/ http://git-scm.com/course/svn.html https://git.wiki.kernel.org/index.php/GitSvnComparison http://zurb.com/article/597/the-one-critical-reason-we-switched-from- • Git Clients – https://code.google.com/p/gitextensions/ – http://sourcetreeapp.com/ – https://github.com/dahlbyk/posh-git
  • 42. Kwen Peterson • http://tinyurl.com/rsdcc13 – https://github.com/Kwen/sdcc2013 – http://speakerrate.com/talks/27811-git-more-done – http://www.slideshare.net/KwenPeterson/git-moredone • • • • @kwenarik #sdcc2013 plus.google.com/+KwenPeterson kwen.peterson@gmail.com https://github.com/Kwen