Fireship · @fireship

Git Explained in 100 Seconds

Uploaded March 2, 2020 · Length 1:57

Git Explained in 100 Seconds

Summary

git basics: creating commits, branches, and merging in a codebase.

  • git
  • version control
  • commit
  • branch
  • merge

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    get a system for keeping track of

  2. 0:02

    changes that happen across a set of

  3. 0:03

    files open a directory on your local

  4. 0:05

    system with an editor like vs code then

  5. 0:07

    run get an it from the command line you

  6. 0:09

    just created a git repository or repo it

  7. 0:12

    lives in this hidden get directory and

  8. 0:13

    keeps track of all the changes that

  9. 0:15

    happen to these files as you work on a

  10. 0:17

    codebase you take snapshots or commits

  11. 0:19

    of the current state of these files

  12. 0:20

    every commit has a unique ID and is

  13. 0:22

    linked to its parent and this means we

  14. 0:24

    can travel back in time to a previous

  15. 0:26

    version of our files notice how our

  16. 0:27

    source control icon is lit up currently

  17. 0:29

    all of our files are untracked because

  18. 0:31

    we need to add them to the repo run get

  19. 0:33

    add to include or stage these files in

  20. 0:35

    the repo then create a snapshot of their

  21. 0:37

    current state by running git commit

  22. 0:39

    along with a message about what you did

  23. 0:41

    to these files congratulations

  24. 0:43

    you just created the first commit on the

  25. 0:44

    head of the master branch in this repo

  26. 0:46

    the changed files disappeared and you're

  27. 0:48

    now on a clean working directory the

  28. 0:49

    head represents the most recent commit

  29. 0:51

    if we make some changes commit them to

  30. 0:53

    the repo the head moves forward but we

  31. 0:55

    still have a reference to our previous

  32. 0:56

    commits so we can always go back to it

  33. 0:58

    but the thing about software is that

  34. 1:00

    it's developed in a nonlinear fashion

  35. 1:01

    you might have multiple teams working on

  36. 1:03

    different features for the same codebase

  37. 1:05

    simultaneously it makes that possible by

  38. 1:08

    branching create one by running git

  39. 1:10

    branch and then rank it check out to

  40. 1:12

    move into that branch you can now safely

  41. 1:13

    work on your feature in this branch

  42. 1:15

    without affecting the code or files in

  43. 1:17

    the master branch the commits you make

  44. 1:19

    here live in an alternate universe with

  45. 1:20

    its own unique history at some point

  46. 1:22

    though you'll likely want to merge this

  47. 1:24

    history with the history and the master

  48. 1:25

    branch when you're ready go back to the

  49. 1:27

    master branch by running git checkout

  50. 1:28

    then run git merge on your

  51. 1:30

    alternate-universe

  52. 1:31

    the tip of your feature branch now

  53. 1:33

    becomes the head of the master branch

  54. 1:34

    where in other words our fragmented

  55. 1:36

    universe has become one unless he ran

  56. 1:39

    into a merge conflict in which case

  57. 1:40

    you'll just have to wait for the sequel

  58. 1:42

    this has been get explained in 100

  59. 1:44

    seconds if you want to see more short

  60. 1:46

    videos like this make sure to hit the

  61. 1:47

    like button subscribe and let me know

  62. 1:49

    what you think in the comments thanks

  63. 1:50

    for watching and I will see you in the

  64. 1:52

    next one

  65. 1:55

    you