SlideShare ist ein Scribd-Unternehmen logo
1 von 68
Everything you wanted to
know about GIT
(BUT WERE AFRAID TO ASK)
ANIMATIONS AHEAD!!!
This deck has plenty of animations to explain
some concepts.
Please view in presentation mode
Setting up
 Apple GIT gotchas:
Xcode ships with its custom version of git. You don’t want this:
$ git --version
git version 2.3.2 (Apple Git-55)
$ which git
/usr/bin/git
Setting Up
 The right git:
Download and install:
http://git-scm.com/download/mac
Set up:
Modify ~/.profile
export PATH=/usr/local/bin:$PATH
$ git --version
git version 2.4.3
Setting Up
 Make life easy for yourself: Autocomplete!
Download: https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
Save to -> ~/.git-completion.bash (Note the dot!)
Add to ~/.profile
# Run git autocomplete
source ~/.git-completion.bash
Verify ->
git check<tab> --autocompletes to--> git checkout
PRO TIP: Also autocompletes branch names!
Setting Up
 Make life easy for yourself, PART 2: Change your terminal prompt!
Download: https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
Save to -> ~/.git-prompt.sh (Note the dot!)
Add to ~/.profile
# Run git prompt enhancements
source ~/.git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWUNTRACKEDFILES=true
export GIT_PS1_SHOWCOLORHINTS=true
export PROMPT_COMMAND='__git_ps1 "w" "$ "'
GIT Init
GIT IS MISUNDERSTOOD.
IT JUST WANTS TO BE YOUR
FRIEND
Git isn’t magic.
BLOBS TREES COMMITS
Git tracks everything. Forever!
 Files (Blobs) are tracked based on content, not on their name.
 Git uses the SHA1 algorithm to create a unique hash (fingerprint) for each file.
foo.txt -> “Hello” -> e965047ad7c57865823c7d992b1d046ea66edf78
How is it calculated?
“blob”+space
Do it yourself! printf ”blob 6000Hellon" | shasum
Null char
Length of content File content
b l o b 6  0 0 0 H e l l o  n
All versions of a file end up as blobs.
E9650
Hello
980a0
Hello World!
53627
Hello World! How are you?
7a27f
Hello World! How are you today?
557db
Hello World
Trees organize (and name) sets of files
E9650
Hello
a69b2
557db
Hello World
8984f
Commit ec445 Commit bd297
Commits give order to trees
E9650
Hello
Tree: a69b2
Author: lmarkus
Message: First Commit
557db
Hello World
bd297ec445
Tree: 8984f
Parent: ec445
Author: lmarkus
Message: Second Commit
Git Recap
 Git saves *everything*
 Git keeps track of what your project looked like at a given time (tree + commit)
 Git keeps a history of the various snapshots as a linked list. (commit -> parent)
The world is my
stage!
The world is my stage!
HEAD STAGE Work Dir
The world is my stage!
HEAD STAGE Work Dir
$ git status
On branch master
nothing to commit, working directory clean
The world is my stage!
HEAD STAGE Work Dir
The world is my stage!
HEAD STAGE Work Dir
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: miner.txt
no changes added to commit (use "git add" and/or "git commit -a")
The world is my stage!
HEAD STAGE Work Dir
$ git add miner.txt
The world is my stage!
HEAD STAGE Work Dir
The world is my stage!
HEAD STAGE Work Dir
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: miner.txt
The world is my stage!
HEAD STAGE Work Dir
The world is my stage!
HEAD STAGE Work Dir
The world is my stage!
HEAD STAGE Work Dir
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: miner.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
sun.txt
The world is my stage!
HEAD STAGE Work Dir
$ git commit -m “Mining is hard”
The world is my stage!
HEAD STAGE Work Dir
“Oops…”
moments
Git Reset
A B C D E
STAGE WORKING DIR
E E
HEAD
Git Reset --soft
A B C D E
STAGE WORKING DIR
E E
HEADgit reset --soft HEAD~1
Git Reset --mixed
A B C D E
STAGE WORKING DIR
D E
HEADgit reset --mixed HEAD~1
E
Git Reset --hard
A B C D E
STAGE WORKING DIR
D D
HEADgit reset --hard HEAD~1
E E
Clean up after
yourself!
Git Rebase - Part I
A B C D E
Created
New Function
Fixed typo Fixed
Another typo
Oops!
Fixed a bug.
Actually,
that wasn’t a bug.
Reverting.
Git Rebase - Part I
A B C D E
Created
New Function
Fixed typo Fixed
Another typo
Oops!
Fixed a bug.
Actually,
that wasn’t a bug.
Reverting.
$ git log --oneline
845c2a5 Actually, that wasn't a bug. Reverting
10ae9b3 Oops, fixed a bug
5c68b04 Fixed Another typo
83775b2 Fixed Typo
099d98e Created New Function
Git rebase --interactive
A B C D E
Created
New Function
Fixed typo Fixed
Another typo
Oops!
Fixed a bug.
Actually,
that wasn’t a bug.
Reverting.
$ git rebase -i HEAD~4
pick 83775b2 Fixed Typo
pick 5c68b04 Fixed Another typo
pick 10ae9b3 Oops, fixed a bug
pick 845c2a5 Actually, that wasn't a bug. Reverting
# Rebase 099d98e..845c2a5 onto 099d98e (4 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
# Note that empty commits are commented out
A B C D E
Created
New Function
Fixed typo Fixed
Another typo
Oops!
Fixed a bug.
Actually,
that wasn’t a bug.
Reverting.
pick 83775b2 Fixed Typo
pick 5c68b04 Fixed Another typo
pick 10ae9b3 Oops, fixed a bug
pick 845c2a5 Actually, that wasn't a bug. Reverting
squash
Git rebase --interactive
Git rebase --interactive
A B C D E
Created
New Function
Fixed typo Fixed
Another typo
Oops!
Fixed a bug.
Actually,
that wasn’t a bug.
Reverting.
pick 83775b2 Fixed Typo
squash 5c68b04 Fixed Another typo
Git rebase --interactive
A B C D E
Created
New Function
Fixed typo Fixed
Another typo
Oops!
Fixed a bug.
Actually,
that wasn’t a bug.
Reverting.
pick 83775b2 Fixed Typo
squash 5c68b04 Fixed Another typo
Git rebase --interactive
A B C D E
Created
New Function
Fixed typo Fixed
Another typo
Oops!
Fixed a bug.
Actually,
that wasn’t a bug.
Reverting.
# This is a combination of 2 commits.
# The first commit's message is:
Fixed Typo
# This is the 2nd commit message:
Fixed Another typo
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
Git rebase --interactive
A B C D E
Created
New Function
Fixed typo Fixed
Another typo
Oops!
Fixed a bug.
Actually,
that wasn’t a bug.
Reverting.
# This is a combination of 2 commits.
# The first commit's message is:
Documentation updates
# This is the 2nd commit message:
# Fixed Another typo
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
Git rebase --interactive
A B C D E
Created
New Function
Fixed typo Fixed
Another typo
Oops!
Fixed a bug.
Actually,
that wasn’t a bug.
Reverting.
$ git log --oneline
779dbd5 Documentation updates
099d98e Created New Function
Branching out
Branches
A B C
MASTER
 Remember: Your git
history is just a linked list
of commits.
 A branch simply
represents a marker
somewhere in this
history. It points to the
latest commit within a
set.
Branches
A B C
MASTER DEVELOP
git checkout -b develop
Branches
A B C
MASTER
D E
DEVELOP
git commit -m ”D”
git commit -m ”E”
Branches
A B C
MASTER
D E
DEVELOP
git checkout master
Branches
A B C
MASTER
D E
DEVELOP
git commit -m “F”
F
Rebase Vs Merge
A B C
MASTER
D E
DEVELOP
F
Merge
A B C
MASTER
D E
DEVELOP
F M Merge commits have TWO
parents. They represent the
point where to branches
became one
git merge develop
X Y
Work can continue after a merge
Rebase
A B C
D E
DEVELOP
MASTER
F
We just re-wrote history!
git rebase develop
Rebase Vs Merge - RECAP
A B C
MASTER
D E
DEVELOP
F M
X Y
A B C
MASTER
D* E* F
Merge
 Very explicit, accurate history
 Visually complex
 Easy to roll back
Rebase
 Linear history
 Easy to understand
 Not historically accurate
 Hard to undo.
Playing well with
others
Forking and Cloning
Develop
Release
Master
Develop
Release
Master
*/Customers-R/activation
* = http://github.paypal.com
*/lmarkus/activation
Develop
Release
Master
originupstream
Forking and Cloning
Develop
Release
Master
lmarkus/activation
Develop
Release
Master
origin
Develop
Release
Master
Customers-R/activation
upstream
person1/activation
person2/activation
person3/activation
Forking and Cloning
UPSTREAM
ORIGIN
LOCAL
git remote update
git rebase upstream/develop
git push origin develop
DEVELOP BRANCH
Forking and Cloning - Common Error #1
UPSTREAM
ORIGIN
LOCAL
git push origin develop
DEVELOP BRANCH
git remote update
git rebase upstream/develop
git push origin develop
Forking and Cloning - Common Error #1
$ git push origin develop
To https://github.paypal.com/lmarkus/activation.git
! [rejected] develop -> develop (non-fast-forward)
error: failed to push some refs to
https://github.paypal.com/lmarkus/activation.git
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Forking and Cloning - Common Error #1
UPSTREAM
ORIGIN
LOCAL
DEVELOP BRANCH
Option 1:
git pull origin develop
git push origin master
Solves the problem, but history
gets messy. Doubled up commits
Forking and Cloning - Common Error #1
UPSTREAM
ORIGIN
LOCAL
DEVELOP BRANCH
Option 2:
git push origin master --force
The Force has a dark side…
You are overwriting history which
may be shared
Resolving merge
conflicts
What happens during a merge
Animals.txt
Animals I like:
Dogs!
Animals.txt
Animals I like:
Cats!
Birds!
master feature1
git merge feature1
Animals.txt
Animals I like:
<<<<<<< HEAD
Dogs!
=======
Cats!
Birds!
>>>>>>> feature1
What happens during a merge
Animals.txt
Animals I like:
Dogs!
Animals.txt
Animals I like:
Cats!
Birds!
master feature1
Animals.txt
Animals I like:
<<<<<<< HEAD
Dogs!
=======
Cats!
Birds!
>>>>>>> feature1
git add Animals.txt
git commit -m “Dogs Rule”
Resolve conflicts the smart way!
Resolve conflicts the smart way!
Shortcuts!
Resolve conflicts the smart way!
Everything you ever wanted to know about Git (But were afraid to ask)

Weitere ähnliche Inhalte

Kürzlich hochgeladen

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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
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
 
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
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Kürzlich hochgeladen (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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
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
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
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
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
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
 
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
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Empfohlen

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

Empfohlen (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

Everything you ever wanted to know about Git (But were afraid to ask)

  • 1. Everything you wanted to know about GIT (BUT WERE AFRAID TO ASK)
  • 2. ANIMATIONS AHEAD!!! This deck has plenty of animations to explain some concepts. Please view in presentation mode
  • 3. Setting up  Apple GIT gotchas: Xcode ships with its custom version of git. You don’t want this: $ git --version git version 2.3.2 (Apple Git-55) $ which git /usr/bin/git
  • 4. Setting Up  The right git: Download and install: http://git-scm.com/download/mac Set up: Modify ~/.profile export PATH=/usr/local/bin:$PATH $ git --version git version 2.4.3
  • 5. Setting Up  Make life easy for yourself: Autocomplete! Download: https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash Save to -> ~/.git-completion.bash (Note the dot!) Add to ~/.profile # Run git autocomplete source ~/.git-completion.bash Verify -> git check<tab> --autocompletes to--> git checkout PRO TIP: Also autocompletes branch names!
  • 6. Setting Up  Make life easy for yourself, PART 2: Change your terminal prompt! Download: https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh Save to -> ~/.git-prompt.sh (Note the dot!) Add to ~/.profile # Run git prompt enhancements source ~/.git-prompt.sh export GIT_PS1_SHOWDIRTYSTATE=true export GIT_PS1_SHOWUNTRACKEDFILES=true export GIT_PS1_SHOWCOLORHINTS=true export PROMPT_COMMAND='__git_ps1 "w" "$ "'
  • 7. GIT Init GIT IS MISUNDERSTOOD. IT JUST WANTS TO BE YOUR FRIEND
  • 8. Git isn’t magic. BLOBS TREES COMMITS
  • 9. Git tracks everything. Forever!  Files (Blobs) are tracked based on content, not on their name.  Git uses the SHA1 algorithm to create a unique hash (fingerprint) for each file. foo.txt -> “Hello” -> e965047ad7c57865823c7d992b1d046ea66edf78
  • 10. How is it calculated? “blob”+space Do it yourself! printf ”blob 6000Hellon" | shasum Null char Length of content File content b l o b 6 0 0 0 H e l l o n
  • 11. All versions of a file end up as blobs. E9650 Hello 980a0 Hello World! 53627 Hello World! How are you? 7a27f Hello World! How are you today? 557db Hello World
  • 12. Trees organize (and name) sets of files E9650 Hello a69b2 557db Hello World 8984f
  • 13. Commit ec445 Commit bd297 Commits give order to trees E9650 Hello Tree: a69b2 Author: lmarkus Message: First Commit 557db Hello World bd297ec445 Tree: 8984f Parent: ec445 Author: lmarkus Message: Second Commit
  • 14.
  • 15. Git Recap  Git saves *everything*  Git keeps track of what your project looked like at a given time (tree + commit)  Git keeps a history of the various snapshots as a linked list. (commit -> parent)
  • 16. The world is my stage!
  • 17. The world is my stage! HEAD STAGE Work Dir
  • 18. The world is my stage! HEAD STAGE Work Dir $ git status On branch master nothing to commit, working directory clean
  • 19. The world is my stage! HEAD STAGE Work Dir
  • 20. The world is my stage! HEAD STAGE Work Dir $ git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: miner.txt no changes added to commit (use "git add" and/or "git commit -a")
  • 21. The world is my stage! HEAD STAGE Work Dir $ git add miner.txt
  • 22. The world is my stage! HEAD STAGE Work Dir
  • 23. The world is my stage! HEAD STAGE Work Dir $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: miner.txt
  • 24. The world is my stage! HEAD STAGE Work Dir
  • 25. The world is my stage! HEAD STAGE Work Dir
  • 26. The world is my stage! HEAD STAGE Work Dir $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: miner.txt Untracked files: (use "git add <file>..." to include in what will be committed) sun.txt
  • 27. The world is my stage! HEAD STAGE Work Dir $ git commit -m “Mining is hard”
  • 28. The world is my stage! HEAD STAGE Work Dir
  • 30. Git Reset A B C D E STAGE WORKING DIR E E HEAD
  • 31. Git Reset --soft A B C D E STAGE WORKING DIR E E HEADgit reset --soft HEAD~1
  • 32. Git Reset --mixed A B C D E STAGE WORKING DIR D E HEADgit reset --mixed HEAD~1 E
  • 33. Git Reset --hard A B C D E STAGE WORKING DIR D D HEADgit reset --hard HEAD~1 E E
  • 35. Git Rebase - Part I A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting.
  • 36. Git Rebase - Part I A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. $ git log --oneline 845c2a5 Actually, that wasn't a bug. Reverting 10ae9b3 Oops, fixed a bug 5c68b04 Fixed Another typo 83775b2 Fixed Typo 099d98e Created New Function
  • 37. Git rebase --interactive A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. $ git rebase -i HEAD~4 pick 83775b2 Fixed Typo pick 5c68b04 Fixed Another typo pick 10ae9b3 Oops, fixed a bug pick 845c2a5 Actually, that wasn't a bug. Reverting # Rebase 099d98e..845c2a5 onto 099d98e (4 command(s)) # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # # These lines can be re-ordered; they are executed from top to bottom. # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. # Note that empty commits are commented out
  • 38. A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. pick 83775b2 Fixed Typo pick 5c68b04 Fixed Another typo pick 10ae9b3 Oops, fixed a bug pick 845c2a5 Actually, that wasn't a bug. Reverting squash Git rebase --interactive
  • 39. Git rebase --interactive A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. pick 83775b2 Fixed Typo squash 5c68b04 Fixed Another typo
  • 40. Git rebase --interactive A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. pick 83775b2 Fixed Typo squash 5c68b04 Fixed Another typo
  • 41. Git rebase --interactive A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. # This is a combination of 2 commits. # The first commit's message is: Fixed Typo # This is the 2nd commit message: Fixed Another typo # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit.
  • 42. Git rebase --interactive A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. # This is a combination of 2 commits. # The first commit's message is: Documentation updates # This is the 2nd commit message: # Fixed Another typo # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit.
  • 43. Git rebase --interactive A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. $ git log --oneline 779dbd5 Documentation updates 099d98e Created New Function
  • 45. Branches A B C MASTER  Remember: Your git history is just a linked list of commits.  A branch simply represents a marker somewhere in this history. It points to the latest commit within a set.
  • 46. Branches A B C MASTER DEVELOP git checkout -b develop
  • 47. Branches A B C MASTER D E DEVELOP git commit -m ”D” git commit -m ”E”
  • 48. Branches A B C MASTER D E DEVELOP git checkout master
  • 49. Branches A B C MASTER D E DEVELOP git commit -m “F” F
  • 50. Rebase Vs Merge A B C MASTER D E DEVELOP F
  • 51. Merge A B C MASTER D E DEVELOP F M Merge commits have TWO parents. They represent the point where to branches became one git merge develop X Y Work can continue after a merge
  • 52. Rebase A B C D E DEVELOP MASTER F We just re-wrote history! git rebase develop
  • 53. Rebase Vs Merge - RECAP A B C MASTER D E DEVELOP F M X Y A B C MASTER D* E* F Merge  Very explicit, accurate history  Visually complex  Easy to roll back Rebase  Linear history  Easy to understand  Not historically accurate  Hard to undo.
  • 55. Forking and Cloning Develop Release Master Develop Release Master */Customers-R/activation * = http://github.paypal.com */lmarkus/activation Develop Release Master originupstream
  • 57. Forking and Cloning UPSTREAM ORIGIN LOCAL git remote update git rebase upstream/develop git push origin develop DEVELOP BRANCH
  • 58. Forking and Cloning - Common Error #1 UPSTREAM ORIGIN LOCAL git push origin develop DEVELOP BRANCH git remote update git rebase upstream/develop git push origin develop
  • 59. Forking and Cloning - Common Error #1 $ git push origin develop To https://github.paypal.com/lmarkus/activation.git ! [rejected] develop -> develop (non-fast-forward) error: failed to push some refs to https://github.paypal.com/lmarkus/activation.git hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  • 60. Forking and Cloning - Common Error #1 UPSTREAM ORIGIN LOCAL DEVELOP BRANCH Option 1: git pull origin develop git push origin master Solves the problem, but history gets messy. Doubled up commits
  • 61. Forking and Cloning - Common Error #1 UPSTREAM ORIGIN LOCAL DEVELOP BRANCH Option 2: git push origin master --force The Force has a dark side… You are overwriting history which may be shared
  • 63. What happens during a merge Animals.txt Animals I like: Dogs! Animals.txt Animals I like: Cats! Birds! master feature1 git merge feature1 Animals.txt Animals I like: <<<<<<< HEAD Dogs! ======= Cats! Birds! >>>>>>> feature1
  • 64. What happens during a merge Animals.txt Animals I like: Dogs! Animals.txt Animals I like: Cats! Birds! master feature1 Animals.txt Animals I like: <<<<<<< HEAD Dogs! ======= Cats! Birds! >>>>>>> feature1 git add Animals.txt git commit -m “Dogs Rule”
  • 65. Resolve conflicts the smart way!
  • 66. Resolve conflicts the smart way! Shortcuts!
  • 67. Resolve conflicts the smart way!