Upgrade to Pro — share decks privately, control downloads, hide ads and more …

~/ git --help

~/ git --help

Talk given at the following conferences/events:
- Android Makers (April / 2023)

Have you ever had an issue with git? Don't know which git command to use? Is your git slow in a big mono repo project?

If you answered YES to any of these questions, this talk is for you. First we will learn how git works under the hood which will give us a better understanding of several git commands. Second we will dive into the git features on Android Studio. Last but not least, share some tips on how to make the most out of git.

After this talk, you will have the right knowledge to master git. Once you start to understand it, the terminology will make more sense and youll eventually learn to love it!

Zhenlei Ji

April 28, 2023
Tweet

More Decks by Zhenlei Ji

Other Decks in Programming

Transcript

  1. 🗓 Agenda 1. A brief history of GIT 2. What

    is GIT? 3. GIT under the hood 4. Learn commands through examples 5. Android Studio + GIT 6. Configuration for your Monorepo 7. Final considerations
  2. https://github.com/git/git “Git is a fast, scalable, distributed revision control system

    with an unusually rich command set that provides both high-level operations and full access to internals.”
  3. https://github.com/git/git “Git is a fast, scalable, distributed revision control system

    with an unusually rich command set that provides both high-level operations and full access to internals.”
  4. unusually rich command set add am archive bisect branch bundle

    checkout cherry-picky citool clean clone commit describe diff fetch format-patch gc gitk grep gui init log maintenance merge mv notes pull push range-diff rebase restore revert rm shortlog show sparse-checkout stash status submodule switch tag worktree
  5. unusually rich command set add am archive bisect branch bundle

    checkout cherry-picky citool clean clone commit describe diff fetch format-patch gc gitk grep gui init log maintenance merge mv notes pull push range-diff rebase restore revert rm shortlog show sparse-checkout stash status submodule switch tag worktree and more…
  6. Internal Git model Tree aabbcc1 (SHA1) +aabbccf: blob = fi

    le.txt +ddee ff 1: blob = other.txt +aabbcc2: tree = folder Tree aabbcc2 (SHA1) + ff feee1: blob = nested.txt +dddee22: blob = other.txt Blob aabbccf (SHA1) +content = fi le.txt Blob ddee ff 1 (SHA1) +content = other.txt Blob ff feee1 (SHA1) +content = folder/nested.txt Blob dddee22 (SHA1) +content = folder/other.txt Commit abc123f (SHA1) +tree = aabbcc1 (SHA1) +author = Zhenlei +commiter = Zhenlei +parent = aaabbb5 +comment = A single commit Tag 7755 ff e (SHA1) +object = abc123f (SHA1) +type = commit +tagger = Zhenlei +comment = My tag comment
  7. Me “GIT is a graph structure of file systems with

    a bunch of commands to modify the graph.” In a nutshell
  8. Create a connection to other repositories ~/ git remote add

    <name> <url> Github Repo (origin) Sophia’s Repo (sophia) Your Repo
  9. Local Branches Remote Branches origin/featureA Sequence of commands C1 C3

    main featureA* origin/main C2 C1 C3 C2 Remote Repository (github) HEAD Working on featureA
  10. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main featureA* origin/main C2 C1 C3 C2 Remote Repository (github) HEAD ~/ git checkout main
  11. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main* featureA origin/main C2 C1 C3 C2 HEAD ~/ git checkout main Remote Repository (github)
  12. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main* featureA origin/main C2 C1 C3 C2 C4 HEAD C4 ~/ git pull Remote Repository (github) git fetch git merge origin/main
  13. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main* featureA origin/main C2 C1 C3 C2 C4 HEAD C4 ~/ git pull Remote Repository (github) git fetch git merge origin/main
  14. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main featureA origin/main C2 C1 C3 C2 C4 HEAD C4 ~/ git checkout -b featureB featureB*
  15. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main featureA origin/main C2 C1 C3 C2 C4 HEAD C4 ~/ git commit -m “C5” featureB* C5
  16. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main featureA origin/main C2 C1 C3 C2 C4 HEAD C4 Update branch with the changes in main featureB* C5 1. git checkout main
  17. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main* featureA origin/main C2 C1 C3 C2 C4 HEAD C4 Update branch with the changes in main featureB C5 1. git checkout main 2. git pull
  18. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main* featureA origin/main C2 C1 C3 C2 C4 HEAD C4 Update branch with the changes in main featureB C5 1. git checkout main 2. git pull Remote Repository (github) git fetch git merge origin/main C6 C6
  19. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main* featureA origin/main C2 C1 C3 C2 C4 HEAD C4 Update branch with the changes in main featureB C5 C6 C6 1. git checkout main 2. git pull 3. git checkout -
  20. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main featureA origin/main C2 C1 C3 C2 C4 C4 Update branch with the changes in main featureB* C5 C6 C6 1. git checkout main 2. git pull 3. git checkout - HEAD
  21. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main featureA origin/main C2 C1 C3 C2 C4 C4 Update branch with the changes in main featureB* C5 C6 C6 1. git checkout main 2. git pull 3. git checkout - 4. git merge main C7 HEAD
  22. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main featureA origin/main C2 C1 C3 C2 C4 C4 Update branch with the changes in main featureB* C5 C6 C6 1. git checkout main 2. git pull 3. git checkout - 4. git merge main C7 HEAD
  23. Local Branches Local Remote Branches origin/featureA Sequence of commands C1

    C3 main featureA* origin/main C2 C1 C3 C2 Remote Repository (github) HEAD Working on featureA git branch -D main
  24. Local Branches Local Remote Branches origin/featureA Sequence of commands featureA*

    origin/main C2 C1 C3 C2 Remote Repository (github) HEAD ~/ git fetch C4 git fetch
  25. Local Branches Local Remote Branches origin/featureA Sequence of commands featureA*

    origin/main C2 C1 C3 C2 HEAD ~/ git checkout -b featureB origin/main C4 featureB
  26. Local Branches Local Remote Branches origin/featureA Sequence of commands featureA

    origin/main C2 C1 C3 C2 ~/ git checkout -b featureB origin/main C4 featureB* HEAD
  27. Local Branches Local Remote Branches origin/featureA Sequence of commands featureA

    origin/main C2 C1 C3 C2 ~/ git commit -m “C5” featureB* C5 HEAD C4
  28. Local Branches Local Remote Branches origin/featureA Sequence of commands featureA

    origin/main C2 C1 C3 C2 Update branch with the changes in main featureB* C5 HEAD C4 C6 Remote Repository (github) git fetch 1. git fetch
  29. Local Branches Local Remote Branches origin/featureA Sequence of commands featureA

    origin/main C2 C1 C3 C2 Update branch with the changes in main featureB* C5 HEAD C4 C6 1. git fetch 2. git rebase origin/main
  30. Local Branches Local Remote Branches origin/featureA Sequence of commands featureA

    origin/main C2 C1 C3 C2 Update branch with the changes in main featureB* C5 C4 C6 1. git fetch 2. git rebase origin/main C5’ HEAD
  31. Merge ~/ git merge featureA featureA C1 featureB* C2 C3

    HEAD C4 What is the parent of C4? 🤔 C2? C3? Both?
  32. ~/ git bisect Use binary search to fi nd the

    commit that introduced a bug 1. git bisect start 2. git bisect bad 3. git bisect good 4. git bisect skip 5. git bisect reset https://git-scm.com/docs/git-bisect
  33. ~/ git bisect run validate.sh 1. 0 (zero) if the

    commit is good 2. 125 if the commit can’t be tested (skip) 3. Anything else (often 127) if the commit is bad https://git-scm.com/docs/git-bisect 😎
  34. Enable auto-prune Delete the refs to branches that don't exist

    on the remote 1. git con fi g --global fetch.prune true 2. git con fi g remote.origin.prune true 1.73s -> 0.02s
  35. References • https://learngitbranching.js.org/ • https://book.git-scm.com/book/en/v2 • https://github.com/git/git • https://medium.com/gitopia/git-a-stupid-content-tracker-d0ef5b86865f •

    https://www.simplilearn.com/git-rebase-vs-merge-article • https://delicious-insights.com/en/posts/git-bisect/ • https://www.atlassian.com/git/tutorials/rewriting-history/git-re fl og • https://github.blog/2015-06-08-how-to-undo-almost-anything-with-git/ • https://github.blog/2022-06-29-improve-git-monorepo-performance-with-a- fi le-system- monitor/