SlideShare a Scribd company logo
1 of 29
use git the proper way
                      or
 How I learned to stop worrying and love rebase


             Jaime Buelta
BASIC CONCEPTS
INDEX         LOCAL REPOSITORY
                    (staging area)       (HEAD)
 WORKPATH




The files in your    What you are        Tracked by git
  hard drive       going to commit
COMMIT TREE
different names for a commit
                    HEAD                               master



                   HEAD^

SHA1: 01d1d5ac9bc28e10902f99a15f9fd979d449adb2

                                                 b12



                   origin/HEAD                   origin/master
Version control systems
are communication tools
 They DON'T replace
 ALL communication
  (just make it easier)
BUSINESS AS USUAL
BASIC LOCAL WORKFLOW

git add (append to index)
git rm (append removal of file to index)
git checkout file (retrieve file from index)
git reset HEAD file (remove from index)
WORKING WITH THE STASH

git stash (push your workpath to the stash)
git stash pop (retrieve last changes on stash)
git stash list (list all changes on stash)
git stash drop (remove last changes on stash)
COMMIT STRATEGIES

commit small, commit often
each commit should be an atomic
related change of the code
add reference number
double check before committing
MEASURE TWICE, CUT ONCE


git status (show index and workpath status)
git log [–graph] (show commit log)
graphical tools to show log
 gitg (Linux), gitx (Mac), tig (Command line),
   gitk, SourceTree
  git gui (can add individual lines to the index)
USE A DIFFTOOL
DIFF AND DIFFTOOL
git diff                   git diff id
                             diff between workpath
  diff between workpath      and id
  and index
                           git diff id id2
git diff -- file              diff between id1 and
                             id2
  diff one file

git diff --cached
  diff between index and
  HEAD
REMOTE REPOSITORY

git fetch (get changes from remote repo)
git pull (get remote branch and apply on top of local)
git push (try to apply local changes to remote repo)
git pull = fetch + merge
git pull --rebase = fetch + rebase
MERGE VS REBASE
                                  develop

                                        new_feature




                                                      new_feature

                    new_feature

develop                                              develop




          merge                             rebase
WORKING WITH BRANCHES

git checkout branch (change to local branch)
git checkout -b branch (create new branch)
git branch –track branch origin/branch
	

 	

 	

 	

 	

 	

 	

 (track remote branch)
git merge branch (merge branch into current
	

   	

   	

   	

   	

   branch)

git rebase branch (rebase current branch on top o
	

   	

   	

   	

   	

   of branch)
NOT ALL BRANCHES ARE
    CREATED EQUAL

Local branches (so be careful when pushing
 changes)

Feature/experimental branch (that should be
 merged back to the main branch)

“Pointer” branch (a particular previous commit of
 permanent branch, like master)

Main, permanent branch (develop/master)
BRANCH STRATEGIES

When working on a feature, merge back often to
avoid big discrepancies with main branch
In general, try to use rebase instead of merge
If hotfixing, use cherry-pick to keep main branch up-
to-date
Limit the number of branches
RECOVERING THE PAST


git checkout id (change to id commit)
git checkout id -- file
                   (change only file to id commit)
WHEN SOMETHING GOES WRONG
        (AND YOU KNOW WHAT IT IS)


Try not to push your error to the repository



git commit --amend (fix your last commit)
git reset (change your index/HEAD)
 git reset –soft (don't change your workspace)

 git reset –hard (change your workspace)
WHEN SOMETHING GOES WRONG
           (MERGE CONFLICTS)



Use a mergetool!
Double-Check before committing
Merging often avoid long and difficult merge
conflicts
WHEN SOMETHING GOES WRONG
  ON A REBASE/MERGE/PULL
       (AND YOU KNOW WHAT IT IS)




git reflog (show branch tag in previous commands)
UNDO A REBASE
                    new_feature


  master
                           ORIG_HEAD



           rebase

git reset –hard ORIG_HEAD
TOO LATE, I PUSHED MY
          CHANGES...
git revert commit (new commit undoing specified commit)
WHEN SOMETHING GOES WRONG
(AND YOU HAVE NO CLUE ABOUT WHAT IT IS)


  git blame file (show each line with writer and SHA)
  git grep pattern (search pattern in git-tracked files)
  git log -Spattern (pickaxe - search commits that
  	

   	

   	

   	

    	

    change pattern)

  gitk file (show commits related to file)
  git bisect (walk through commits to find which one
  	

   	

   	

         introduces a bug)
SOME CONFIGURATION
         OPTIONS
COLORS!
  git config color.ui true
ssh keys to repo
  No more typing passwords
merge tool and difftool
autocorrect
  git config help.autocorrect 2 (0.2 sec)
RESOURCES

Git doc (same as man files) http://www.kernel.org/pub/
software/scm/git/docs/

Pro git http://progit.org/book/ (lot about the internals)

Git community book http://book.git-scm.com/

Cheat sheet http://ndpsoftware.com/git-cheatsheet.html

StackOverflow http://stackoverflow.com/
QUESTIONS?


   Thanks for your
      attention

                @jaimebuelta
  wrongsideofmemphis.worspress.com

More Related Content

Similar to Use git the proper way

Similar to Use git the proper way (20)

Session git
Session gitSession git
Session git
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
 
Git workshop
Git workshopGit workshop
Git workshop
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
 
Git, from the beginning
Git, from the beginningGit, from the beginning
Git, from the beginning
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use It
 
Git commands
Git commandsGit commands
Git commands
 
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)
 
Git
GitGit
Git
 
Git
GitGit
Git
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
Source control management
Source control managementSource control management
Source control management
 
Git like a pro EDD18 - Full edition
Git like a pro EDD18 - Full editionGit like a pro EDD18 - Full edition
Git like a pro EDD18 - Full edition
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Git basics a starter on git and its ecosystem
Git basics  a starter on git and its ecosystemGit basics  a starter on git and its ecosystem
Git basics a starter on git and its ecosystem
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
 
How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get Git
 
Git slides
Git slidesGit slides
Git slides
 

Recently uploaded

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Recently uploaded (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

Use git the proper way

  • 1. use git the proper way or How I learned to stop worrying and love rebase Jaime Buelta
  • 3. INDEX LOCAL REPOSITORY (staging area) (HEAD) WORKPATH The files in your What you are Tracked by git hard drive going to commit
  • 5. different names for a commit HEAD master HEAD^ SHA1: 01d1d5ac9bc28e10902f99a15f9fd979d449adb2 b12 origin/HEAD origin/master
  • 6. Version control systems are communication tools They DON'T replace ALL communication (just make it easier)
  • 8. BASIC LOCAL WORKFLOW git add (append to index) git rm (append removal of file to index) git checkout file (retrieve file from index) git reset HEAD file (remove from index)
  • 9. WORKING WITH THE STASH git stash (push your workpath to the stash) git stash pop (retrieve last changes on stash) git stash list (list all changes on stash) git stash drop (remove last changes on stash)
  • 10. COMMIT STRATEGIES commit small, commit often each commit should be an atomic related change of the code add reference number double check before committing
  • 11. MEASURE TWICE, CUT ONCE git status (show index and workpath status) git log [–graph] (show commit log) graphical tools to show log gitg (Linux), gitx (Mac), tig (Command line), gitk, SourceTree git gui (can add individual lines to the index)
  • 13. DIFF AND DIFFTOOL git diff git diff id diff between workpath diff between workpath and id and index git diff id id2 git diff -- file diff between id1 and id2 diff one file git diff --cached diff between index and HEAD
  • 14. REMOTE REPOSITORY git fetch (get changes from remote repo) git pull (get remote branch and apply on top of local) git push (try to apply local changes to remote repo) git pull = fetch + merge git pull --rebase = fetch + rebase
  • 15. MERGE VS REBASE develop new_feature new_feature new_feature develop develop merge rebase
  • 16. WORKING WITH BRANCHES git checkout branch (change to local branch) git checkout -b branch (create new branch) git branch –track branch origin/branch (track remote branch) git merge branch (merge branch into current branch) git rebase branch (rebase current branch on top o of branch)
  • 17. NOT ALL BRANCHES ARE CREATED EQUAL Local branches (so be careful when pushing changes) Feature/experimental branch (that should be merged back to the main branch) “Pointer” branch (a particular previous commit of permanent branch, like master) Main, permanent branch (develop/master)
  • 18. BRANCH STRATEGIES When working on a feature, merge back often to avoid big discrepancies with main branch In general, try to use rebase instead of merge If hotfixing, use cherry-pick to keep main branch up- to-date Limit the number of branches
  • 19. RECOVERING THE PAST git checkout id (change to id commit) git checkout id -- file (change only file to id commit)
  • 20.
  • 21. WHEN SOMETHING GOES WRONG (AND YOU KNOW WHAT IT IS) Try not to push your error to the repository git commit --amend (fix your last commit) git reset (change your index/HEAD) git reset –soft (don't change your workspace) git reset –hard (change your workspace)
  • 22. WHEN SOMETHING GOES WRONG (MERGE CONFLICTS) Use a mergetool! Double-Check before committing Merging often avoid long and difficult merge conflicts
  • 23. WHEN SOMETHING GOES WRONG ON A REBASE/MERGE/PULL (AND YOU KNOW WHAT IT IS) git reflog (show branch tag in previous commands)
  • 24. UNDO A REBASE new_feature master ORIG_HEAD rebase git reset –hard ORIG_HEAD
  • 25. TOO LATE, I PUSHED MY CHANGES... git revert commit (new commit undoing specified commit)
  • 26. WHEN SOMETHING GOES WRONG (AND YOU HAVE NO CLUE ABOUT WHAT IT IS) git blame file (show each line with writer and SHA) git grep pattern (search pattern in git-tracked files) git log -Spattern (pickaxe - search commits that change pattern) gitk file (show commits related to file) git bisect (walk through commits to find which one introduces a bug)
  • 27. SOME CONFIGURATION OPTIONS COLORS! git config color.ui true ssh keys to repo No more typing passwords merge tool and difftool autocorrect git config help.autocorrect 2 (0.2 sec)
  • 28. RESOURCES Git doc (same as man files) http://www.kernel.org/pub/ software/scm/git/docs/ Pro git http://progit.org/book/ (lot about the internals) Git community book http://book.git-scm.com/ Cheat sheet http://ndpsoftware.com/git-cheatsheet.html StackOverflow http://stackoverflow.com/
  • 29. QUESTIONS? Thanks for your attention @jaimebuelta wrongsideofmemphis.worspress.com

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. Not a fan of gui tools for everything, though\n
  13. Very useful also for merges\n
  14. \n
  15. \n
  16. \n
  17. \n
  18. For pointer branches, ideally, should be merged back immediately when a hot fix arrises\n
  19. \n
  20. \n
  21. When something goes wrong\n
  22. \n
  23. Run tests, if possible\n
  24. Reflog shows the pointers to the branches, etc on the last actions. Good for bad rebases/merges/pull\n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n