< Return to Video

Lecture 6: Version Control (git) (2020)

  • 0:01 - 0:06
    alright let's get started with today's
  • 0:04 - 0:08
    lecture so actually before we get
  • 0:06 - 0:10
    started one quick note about office
  • 0:08 - 0:11
    hours it seemed from the poll that some
  • 0:10 - 0:13
    people were under the impression that
  • 0:11 - 0:16
    the office hours that follows each
  • 0:13 - 0:18
    lecture is just about that day's
  • 0:16 - 0:19
    lectures topics and this is not the case
  • 0:18 - 0:21
    you can come to office hours and ask us
  • 0:19 - 0:22
    questions about any lecture whether it's
  • 0:21 - 0:24
    the previous day or from the previous
  • 0:22 - 0:26
    week or even things not exactly covered
  • 0:24 - 0:29
    in this class that you're just curious
  • 0:26 - 0:33
    about so yeah come to office hours with
  • 0:29 - 0:37
    questions about anything office hours
  • 0:33 - 0:38
    are in the 32 g9 lounge so building 32
  • 0:37 - 0:41
    also known as a Stata Center has two
  • 0:38 - 0:42
    towers the G tower and the D tower so
  • 0:41 - 0:44
    we're in the gates tower on the ninth
  • 0:42 - 0:45
    floor so if you take the elevator all
  • 0:44 - 0:50
    the way up there's the lounge right in
  • 0:45 - 0:51
    front of you okay cool so today we're
  • 0:50 - 0:53
    going to be talking about version
  • 0:51 - 0:56
    control systems so I just want to get a
  • 0:53 - 0:58
    sense of whether you guys have used
  • 0:56 - 1:00
    version control systems before so could
  • 0:58 - 1:01
    you raise your hand if you have any
  • 1:00 - 1:03
    experience with git or any other version
  • 1:01 - 1:06
    control system like subversion or
  • 1:03 - 1:09
    mercurial or anything else oh great so
  • 1:06 - 1:11
    that's a good number of you so I won't
  • 1:09 - 1:13
    talk about version control systems in
  • 1:11 - 1:15
    general way too much then we'll pretty
  • 1:13 - 1:17
    quickly get into the details of git and
  • 1:15 - 1:19
    like it's data model and its internals
  • 1:17 - 1:21
    but just as a quick summary version
  • 1:19 - 1:23
    control systems are tools that are used
  • 1:21 - 1:25
    to keep track of changes to source code
  • 1:23 - 1:29
    or other collections of files or folders
  • 1:25 - 1:32
    and as the name implies these tools help
  • 1:29 - 1:34
    track the history of changes to some set
  • 1:32 - 1:36
    of documents and in addition to doing
  • 1:34 - 1:38
    that they facilitate collaboration so
  • 1:36 - 1:42
    they're really useful for working with a
  • 1:38 - 1:44
    group of people on a software project
  • 1:42 - 1:46
    Virna control systems track changes to a
  • 1:44 - 1:49
    folder and its contents in a series of
  • 1:46 - 1:50
    snapshots so you capture the entire
  • 1:49 - 1:52
    state of a folder and everything inside
  • 1:50 - 1:54
    like a software project and you have
  • 1:52 - 1:56
    multiple of these in a series of
  • 1:54 - 1:58
    snapshots each snapshot encapsulate the
  • 1:56 - 1:59
    entire set of files and folders
  • 1:58 - 2:01
    contained within some top-level
  • 1:59 - 2:03
    directory and then version control
  • 2:01 - 2:05
    systems also maintain a bunch of
  • 2:03 - 2:07
    metadata along with the actual changes
  • 2:05 - 2:09
    to the content and this is to make it
  • 2:07 - 2:11
    possible to figure things out like who
  • 2:09 - 2:13
    authored a particular change to a
  • 2:11 - 2:14
    particular file or when was a particular
  • 2:13 - 2:15
    change made
  • 2:14 - 2:17
    and slow version control systems
  • 2:15 - 2:19
    maintain metadata like authors and
  • 2:17 - 2:21
    commit timestamps and you can also
  • 2:19 - 2:24
    attach extra messages to these snapshots
  • 2:21 - 2:25
    and things like that and so why is
  • 2:24 - 2:26
    version control useful
  • 2:25 - 2:29
    well it's useful even when you're
  • 2:26 - 2:31
    working on projects by yourself so you
  • 2:29 - 2:33
    can use it to look at old versions of
  • 2:31 - 2:34
    code you've written figure out like why
  • 2:33 - 2:37
    something was changed by looking at
  • 2:34 - 2:39
    commit messages work on different things
  • 2:37 - 2:41
    in parallel without conflicts by using
  • 2:39 - 2:43
    different branches of development or be
  • 2:41 - 2:45
    able to work on bug fixes while keeping
  • 2:43 - 2:46
    work on different features independent
  • 2:45 - 2:48
    things like that and so it's an
  • 2:46 - 2:50
    invaluable tool even if you're working
  • 2:48 - 2:53
    just by yourself even on a small scale
  • 2:50 - 2:56
    project like I think the instructors of
  • 2:53 - 2:58
    this course use git even on things like
  • 2:56 - 3:00
    homework assignments or class projects
  • 2:58 - 3:02
    even small scale things in addition to
  • 3:00 - 3:05
    our research or larger software projects
  • 3:02 - 3:07
    and then of course version control is a
  • 3:05 - 3:09
    really powerful tool for working with
  • 3:07 - 3:12
    other people so it's useful for sending
  • 3:09 - 3:14
    patches of code around resolving
  • 3:12 - 3:15
    conflicts when different people are
  • 3:14 - 3:19
    working on the same piece of code at the
  • 3:15 - 3:20
    same time things like that and so it's a
  • 3:19 - 3:22
    really powerful tool for working by
  • 3:20 - 3:25
    yourself or with others and it also has
  • 3:22 - 3:27
    a neat functionality to let you answer
  • 3:25 - 3:28
    questions that would otherwise be kind
  • 3:27 - 3:31
    of hard to answer like who wrote a
  • 3:28 - 3:33
    particular module in a software project
  • 3:31 - 3:35
    or who edited a particular line in a
  • 3:33 - 3:37
    particular software project why was this
  • 3:35 - 3:39
    particular line change when was it
  • 3:37 - 3:41
    changed by whom things like that and
  • 3:39 - 3:43
    version control systems also have some
  • 3:41 - 3:44
    really powerful functionality that we
  • 3:43 - 3:45
    might cover at the end of today's
  • 3:44 - 3:46
    lecture
  • 3:45 - 3:48
    or you can find the lecture notes if we
  • 3:46 - 3:49
    don't have time to do things like
  • 3:48 - 3:51
    supposed to have some project you've
  • 3:49 - 3:52
    been working on for a couple years and
  • 3:51 - 3:54
    then you notice that some funny thing
  • 3:52 - 3:55
    about the project was broken like you
  • 3:54 - 3:58
    have some unit test that doesn't pass
  • 3:55 - 3:59
    anymore and it wasn't broken just now it
  • 3:58 - 4:02
    was broken some time ago and you don't
  • 3:59 - 4:04
    know exactly when this regression was
  • 4:02 - 4:06
    introduced well written control systems
  • 4:04 - 4:08
    have a way of automatically identifying
  • 4:06 - 4:10
    this like you can take it and give it a
  • 4:08 - 4:11
    unit test that's currently failing but
  • 4:10 - 4:13
    you know was passing at some point in
  • 4:11 - 4:15
    the past and it can binary search your
  • 4:13 - 4:17
    history and figure out exactly what
  • 4:15 - 4:20
    change to your code made it break so
  • 4:17 - 4:21
    lots of really powerful fancy features
  • 4:20 - 4:24
    if you know how to use these tools
  • 4:21 - 4:24
    properly
  • 4:26 - 4:30
    there are a number of version control
  • 4:28 - 4:32
    systems out there and get has become
  • 4:30 - 4:33
    kind of the de facto standard for
  • 4:32 - 4:36
    version control so that's what we're
  • 4:33 - 4:39
    going to be covering in today's lecture
  • 4:36 - 4:42
    one comic I want to show you which was
  • 4:39 - 4:48
    on the screen before hand let me bring
  • 4:42 - 4:50
    it back up so this is an xkcd comic that
  • 4:48 - 4:52
    illustrates gets reputation so let me
  • 4:50 - 4:55
    read it out loud for you
  • 4:52 - 4:57
    this is good it tries collaborative work
  • 4:55 - 4:59
    on projects through a beautiful
  • 4:57 - 5:02
    distributed graph theory tree model cool
  • 4:59 - 5:03
    how do we use it no idea just memorize
  • 5:02 - 5:05
    these shell commands and type them to
  • 5:03 - 5:07
    sync up if you get errors save your work
  • 5:05 - 5:12
    elsewhere delete the project and
  • 5:07 - 5:13
    download a fresh copy so maybe some
  • 5:12 - 5:14
    people may not want to raise their hands
  • 5:13 - 5:15
    for this but raise your hand if you've
  • 5:14 - 5:17
    ever done this before
  • 5:15 - 5:20
    I certainly have when I was learning
  • 5:17 - 5:22
    this tool so good number of you here
  • 5:20 - 5:24
    have done this before so the goal of
  • 5:22 - 5:27
    this lecture is to make it so you don't
  • 5:24 - 5:32
    have to do this anymore unfortunately as
  • 5:27 - 5:34
    this comic illustrates gets interface is
  • 5:32 - 5:36
    a pretty terribly designed interface
  • 5:34 - 5:38
    it's a leaky abstraction and so for this
  • 5:36 - 5:40
    reason we believe that learning get
  • 5:38 - 5:42
    topped down starting with the interface
  • 5:40 - 5:45
    is maybe not the best way to go and it
  • 5:42 - 5:47
    can lead to some confusion it's possible
  • 5:45 - 5:48
    like this comic shows to memorize a
  • 5:47 - 5:50
    handful of commands and think of them as
  • 5:48 - 5:53
    magic incantations and why everything's
  • 5:50 - 5:54
    working all right it kind of works out
  • 5:53 - 5:56
    all right but then you have to follow
  • 5:54 - 5:57
    the approach of this comic whenever
  • 5:56 - 6:01
    things go wrong
  • 5:57 - 6:03
    so while git has an ugly interface its
  • 6:01 - 6:06
    underlying design and ideas are actually
  • 6:03 - 6:09
    pretty beautiful an ugly interface has
  • 6:06 - 6:10
    to be memorized but the beautiful ideas
  • 6:09 - 6:12
    underlying git can actually be
  • 6:10 - 6:15
    understood and once you understand gets
  • 6:12 - 6:17
    internals its data model which is
  • 6:15 - 6:19
    actually not that complicated then you
  • 6:17 - 6:21
    can learn the interface to get you
  • 6:19 - 6:23
    you'll have to memorize some things but
  • 6:21 - 6:25
    you can understand what exactly certain
  • 6:23 - 6:28
    commands do by understanding how they
  • 6:25 - 6:29
    manipulate the underlying data model and
  • 6:28 - 6:31
    so the way we're going to teach get
  • 6:29 - 6:33
    today is first talk about the data model
  • 6:31 - 6:36
    almost in abstract talk about how we
  • 6:33 - 6:38
    might model files and folders snapshots
  • 6:36 - 6:39
    of history and how they relate to each
  • 6:38 - 6:40
    other
  • 6:39 - 6:42
    then after that we'll walk you through
  • 6:40 - 6:44
    some get commands and then finally in
  • 6:42 - 6:46
    the resources and exercises will link
  • 6:44 - 6:47
    you to tutorials that'll teach you all
  • 6:46 - 6:48
    the specifics because there are lots of
  • 6:47 - 6:51
    different commands that you will need to
  • 6:48 - 6:54
    learn eventually any questions so far
  • 6:51 - 6:59
    about our teaching approach for today
  • 6:54 - 7:01
    cool great so let's get started there
  • 6:59 - 7:04
    are probably many ad hoc approaches you
  • 7:01 - 7:05
    could take to version control and I'm
  • 7:04 - 7:07
    guessing some of you may have done this
  • 7:05 - 7:08
    before like say you have some file or
  • 7:07 - 7:10
    folder we have a bunch of different
  • 7:08 - 7:12
    files corresponding system software
  • 7:10 - 7:14
    project and you want to track changes
  • 7:12 - 7:16
    you could just say every day make a copy
  • 7:14 - 7:17
    of that entire folder and give that
  • 7:16 - 7:19
    folder a timestamp when you want to do
  • 7:17 - 7:20
    things like collaborate with other
  • 7:19 - 7:22
    people you could take the entire folder
  • 7:20 - 7:24
    turned it into a zip archive and email
  • 7:22 - 7:26
    it to somebody and then whenever you and
  • 7:24 - 7:28
    your buddy are working on two different
  • 7:26 - 7:29
    features of a software project you can
  • 7:28 - 7:31
    work on them in parallel then one of you
  • 7:29 - 7:32
    emails the zip file to the other person
  • 7:31 - 7:34
    and then you manually copy and paste the
  • 7:32 - 7:36
    appropriate segments from their code
  • 7:34 - 7:38
    into your code so that eventually you
  • 7:36 - 7:41
    end up with one piece of code that has
  • 7:38 - 7:44
    both of your features in it this kind of
  • 7:41 - 7:45
    sort of works raise your hand if you've
  • 7:44 - 7:47
    done this before
  • 7:45 - 7:52
    I certainly have still a decent number
  • 7:47 - 7:53
    of you get let's us not do this sort of
  • 7:52 - 7:55
    thing
  • 7:53 - 7:56
    it is a well-thought-out model that kind
  • 7:55 - 7:58
    of facilitates these sorts of
  • 7:56 - 8:00
    interactions things that you might want
  • 7:58 - 8:02
    to do like tracking your own history on
  • 8:00 - 8:05
    your in project or collaboration or
  • 8:02 - 8:06
    things like that so git has a well
  • 8:05 - 8:08
    thought-out model that enables things
  • 8:06 - 8:10
    like branches and collaboration and
  • 8:08 - 8:13
    merging changes from other people all
  • 8:10 - 8:15
    sorts of neat stuff get models history
  • 8:13 - 8:17
    is a collection of files and folders
  • 8:15 - 8:18
    within some top-level directory so
  • 8:17 - 8:20
    you're probably familiar with this
  • 8:18 - 8:21
    abstraction just from files and folders
  • 8:20 - 8:23
    on your own computer and so here's one
  • 8:21 - 8:25
    example like you might have some
  • 8:23 - 8:28
    top-level directory I'll just call this
  • 8:25 - 8:30
    like root in parentheses and this
  • 8:28 - 8:32
    directory might have say a folder in it
  • 8:30 - 8:36
    called foo and this folder inside of it
  • 8:32 - 8:38
    might have a file called bar dot txt and
  • 8:36 - 8:43
    this might have some contents in it like
  • 8:38 - 8:45
    say this says hello world and then maybe
  • 8:43 - 8:47
    this top-level directory it has one
  • 8:45 - 8:49
    folder in it it caalso have another file
  • 8:47 - 8:52
    in it so say there's some other file
  • 8:49 - 8:59
    and this file also has some contents in
  • 8:52 - 9:02
    it all right
  • 8:59 - 9:03
    simple enough the terminology get uses
  • 9:02 - 9:08
    for these different things for files and
  • 9:03 - 9:16
    folders is this and the top-level thing
  • 9:08 - 9:19
    are called trees so this is a folder and
  • 9:16 - 9:27
    then these things what we normally call
  • 9:19 - 9:29
    files are called blogs all right ok so
  • 9:27 - 9:33
    now we have a model of files and folders
  • 9:29 - 9:35
    and this is a recursive data structure
  • 9:33 - 9:38
    trees can contain other trees and then
  • 9:35 - 9:41
    trees can contain both trees and files
  • 9:38 - 9:44
    obviously files can't contain trees all
  • 9:41 - 9:48
    right so now we have a model of files
  • 9:44 - 9:49
    and folders and the kind of top-level of
  • 9:48 - 9:52
    this thing the thing I've just labeled
  • 9:49 - 9:53
    root is the directory being tracked like
  • 9:52 - 9:55
    you might have some folder on your
  • 9:53 - 9:59
    computer corresponding to a software
  • 9:55 - 10:00
    project now how do you model history
  • 9:59 - 10:02
    once you have a model of files and
  • 10:00 - 10:04
    folders well you can imagine one way of
  • 10:02 - 10:06
    doing it which is you take a snapshot of
  • 10:04 - 10:08
    this entire thing and then history is
  • 10:06 - 10:10
    just a linear sequence of snapshots like
  • 10:08 - 10:11
    you might imagine that it's you can
  • 10:10 - 10:14
    almost think of it like you have copies
  • 10:11 - 10:16
    of the folder which are dated and
  • 10:14 - 10:19
    time-stamped well it doesn't use a
  • 10:16 - 10:20
    simple linear model like that it uses
  • 10:19 - 10:22
    something a little bit fancier you might
  • 10:20 - 10:24
    have heard this terminology before but
  • 10:22 - 10:26
    git uses a directed acyclic graph to
  • 10:24 - 10:28
    model history and this might sound like
  • 10:26 - 10:29
    a bunch of fancy math words but it's
  • 10:28 - 10:33
    actually not all that complicated
  • 10:29 - 10:35
    so in get each snapshot has some number
  • 10:33 - 10:37
    of parents and basically want to know
  • 10:35 - 10:39
    like what change preceded what other
  • 10:37 - 10:42
    change so suppose here I'm going to use
  • 10:39 - 10:45
    circles to refer to individual snapshots
  • 10:42 - 10:47
    this is the entire contents within this
  • 10:45 - 10:50
    tree so all the files and folders in my
  • 10:47 - 10:53
    project my entire project may be in some
  • 10:50 - 10:55
    state and then I edit some files and now
  • 10:53 - 10:56
    it's in some other state and then I add
  • 10:55 - 10:59
    some more files and that's in some other
  • 10:56 - 11:02
    state and every state points back to
  • 10:59 - 11:03
    which state preceded it this so far is a
  • 11:02 - 11:05
    linear history
  • 11:03 - 11:09
    but it lets us do something a little bit
  • 11:05 - 11:11
    fancier than this you can also from a
  • 11:09 - 11:15
    certain snapshot fork your history and
  • 11:11 - 11:19
    say I want to base changes off of this
  • 11:15 - 11:23
    version and create a new snapshot like
  • 11:19 - 11:24
    this so this way of modeling history
  • 11:23 - 11:26
    allows you to do things like okay I'm
  • 11:24 - 11:28
    working on my project this is my main
  • 11:26 - 11:30
    line of development I go up to here and
  • 11:28 - 11:32
    now I have two different tasks I want to
  • 11:30 - 11:34
    work on suppose on one hand I have some
  • 11:32 - 11:35
    fancy new feature I want to add to my
  • 11:34 - 11:37
    project and so I'm going to be working
  • 11:35 - 11:38
    on that for a couple days but separately
  • 11:37 - 11:40
    from that somebody's reported a bug to
  • 11:38 - 11:42
    me and I need to go chase down that bug
  • 11:40 - 11:44
    and fix it well instead of working on
  • 11:42 - 11:45
    all that stuff kind of concurrently at
  • 11:44 - 11:46
    the same time in the same line of
  • 11:45 - 11:49
    development
  • 11:46 - 11:51
    git has its way of branching the history
  • 11:49 - 11:53
    into two separate Forks and working on
  • 11:51 - 11:55
    different things in parallel temporarily
  • 11:53 - 11:57
    in a way that are unrelated to each
  • 11:55 - 11:59
    other so I could take this base snapshot
  • 11:57 - 12:01
    like my project is in some state where
  • 11:59 - 12:03
    it works and then from here I could
  • 12:01 - 12:05
    implement a new feature that creates a
  • 12:03 - 12:08
    new snapshot so this has the base
  • 12:05 - 12:12
    project plus a new feature so I'll do
  • 12:08 - 12:14
    like plus feature and then similarly
  • 12:12 - 12:15
    separately from this I could go back to
  • 12:14 - 12:17
    this original snapshot because I don't
  • 12:15 - 12:20
    want to do bug fixing while implementing
  • 12:17 - 12:21
    my new feature go here and then work on
  • 12:20 - 12:25
    my bug fix and create a different
  • 12:21 - 12:25
    snapshot so this has only the bug fix
  • 12:26 - 12:30
    but not the feature and then finally
  • 12:29 - 12:32
    once I've done these two separate things
  • 12:30 - 12:34
    in parallel eventually I want to
  • 12:32 - 12:35
    incorporate them all into my common
  • 12:34 - 12:37
    source code that has both the feature
  • 12:35 - 12:40
    and the bug fix so eventually I might
  • 12:37 - 12:42
    author a new snapshot by merging the
  • 12:40 - 12:44
    changes present in these two different
  • 12:42 - 12:47
    snapshots and so this one I'll have both
  • 12:44 - 12:55
    of these snapshots as parents and this
  • 12:47 - 12:58
    version here will have both the feature
  • 12:55 - 13:00
    and my bug fix so does it make sense why
  • 12:58 - 13:02
    get models history in a way that's a
  • 13:00 - 13:05
    little bit fancier than just a sequence
  • 13:02 - 13:06
    of snapshots of my files and folders why
  • 13:05 - 13:08
    I want to be able to support branching
  • 13:06 - 13:10
    to work on things in parallel and then
  • 13:08 - 13:11
    also merging to combine changes from
  • 13:10 - 13:14
    different parallel branches of
  • 13:11 - 13:14
    development question
  • 13:17 - 13:22
    yeah so that's an excellent point it
  • 13:21 - 13:23
    seems that when you merge things you
  • 13:22 - 13:26
    could create errors that weren't
  • 13:23 - 13:28
    anticipated you could imagine here that
  • 13:26 - 13:30
    this feature actually changes something
  • 13:28 - 13:31
    that makes this bug-fix redundant or you
  • 13:30 - 13:33
    could imagine this bug fix breaking this
  • 13:31 - 13:35
    feature or something like that oh that's
  • 13:33 - 13:37
    a really good point that's a something
  • 13:35 - 13:39
    known as merge conflicts and this is
  • 13:37 - 13:41
    something that git will try to do like
  • 13:39 - 13:43
    when you merge your parallel branches of
  • 13:41 - 13:44
    development it will try to automatically
  • 13:43 - 13:47
    combine the changes in a way such that
  • 13:44 - 13:49
    it retains all the important changes but
  • 13:47 - 13:50
    if it gets confused it will report a
  • 13:49 - 13:52
    merge conflict and then leave it up to
  • 13:50 - 13:55
    you the programmer to figure out how to
  • 13:52 - 13:56
    combine kind of concurrent changes to
  • 13:55 - 13:58
    the same files or things like that and
  • 13:56 - 14:06
    then get has some tools for facilitating
  • 13:58 - 14:08
    this any other questions great ok so now
  • 14:06 - 14:10
    we have a model files and folders and
  • 14:08 - 14:11
    then we have a model of history how
  • 14:10 - 14:12
    different snapshots of our code relate
  • 14:11 - 14:15
    to each other
  • 14:12 - 14:18
    one little detail here is that each of
  • 14:15 - 14:20
    these circles so they kind of correspond
  • 14:18 - 14:22
    to a snapshot like a tree with files and
  • 14:20 - 14:25
    folders but they also have a little bit
  • 14:22 - 14:29
    of metadata so like inside here we might
  • 14:25 - 14:34
    have like the author of this commit is
  • 14:29 - 14:36
    me and we might have other metadata like
  • 14:34 - 14:39
    some message associated with this commit
  • 14:36 - 14:41
    I might describe what kinds of changes
  • 14:39 - 14:44
    I've made that are present in this
  • 14:41 - 14:44
    snapshot but not the previous one
  • 14:48 - 15:01
    that is not really the chair class so
  • 14:59 - 15:03
    next we're going to talk about kind of
  • 15:01 - 15:08
    one level lower than this like how
  • 15:03 - 15:10
    exactly is this represented as a as a
  • 15:08 - 15:11
    data structure inside get and so I'm
  • 15:10 - 15:12
    actually going to write down pseudocode
  • 15:11 - 15:16
    because I think it's actually easiest to
  • 15:12 - 15:21
    understand this way so first we have
  • 15:16 - 15:25
    files so a log is just a bunch of bytes
  • 15:21 - 15:25
    so I'll say this is an array of bytes
  • 15:26 - 15:34
    okay then what is a tree remember that
  • 15:32 - 15:39
    this is just a folder of what are
  • 15:34 - 15:42
    folders they're mappings from the
  • 15:39 - 15:45
    filename or directoryname to the actual
  • 15:42 - 15:50
    contents and the contents are either
  • 15:45 - 15:56
    another tree like a subtree or the file
  • 15:50 - 15:57
    and then finally we have the last thing
  • 15:56 - 15:59
    there what I've been calling snapshots
  • 15:57 - 16:04
    so far and get terminology those are
  • 15:59 - 16:04
    called commits and so what does a commit
  • 16:04 - 16:10
    [Applause]
  • 16:07 - 16:14
    it's a bunch of stuff commits have
  • 16:10 - 16:17
    parents that describes what precede them
  • 16:14 - 16:18
    so in the case of most normal commits
  • 16:17 - 16:20
    they have one parent like what they came
  • 16:18 - 16:25
    from what merge commits can have
  • 16:20 - 16:31
    multiple parents so parents are an array
  • 16:25 - 16:39
    of commits and then I have some metadata
  • 16:31 - 16:39
    like the author and maybe a message
  • 16:42 - 16:51
    and then finally the actual contents the
  • 16:48 - 16:54
    snapshot which is a tree that's the
  • 16:51 - 16:56
    top-level tree corresponding to a
  • 16:54 - 16:58
    particular commitment so this is a
  • 16:56 - 17:01
    really clean simple model of history and
  • 16:58 - 17:04
    this is basically all there is to how
  • 17:01 - 17:10
    get models history any questions about
  • 17:04 - 17:13
    that all right so now we have that going
  • 17:10 - 17:15
    a little bit deeper let's talk about how
  • 17:13 - 17:17
    it actually stores and addresses this
  • 17:15 - 17:19
    actual data like at some point this
  • 17:17 - 17:26
    actually has to turn to data on disk
  • 17:19 - 17:28
    right so get defines an object kind of a
  • 17:26 - 17:30
    big standing term but an object is any
  • 17:28 - 17:40
    one of those three things so it's a blob
  • 17:30 - 17:43
    or a tree tree or a commit and then in
  • 17:40 - 17:46
    get all objects are content addressed
  • 17:43 - 17:48
    so what get maintains on disk and you
  • 17:46 - 18:00
    can actually we can look at this later
  • 17:48 - 18:04
    is a set of objects maintained as this
  • 18:00 - 18:06
    content address store so if you have any
  • 18:04 - 18:10
    one of these objects the way you put it
  • 18:06 - 18:13
    into this store is its key is the hash
  • 18:10 - 18:17
    of the object so like in pseudocode I
  • 18:13 - 18:20
    might say that to store a particular
  • 18:17 - 18:26
    object o what I do is I compute its ID
  • 18:20 - 18:26
    by taking the sha-1 hash of o and then I
  • 18:27 - 18:36
    put it into my objects map store it to
  • 18:31 - 18:40
    disk a quick show of hands who here
  • 18:36 - 18:42
    knows what a hash function is all right
  • 18:40 - 18:44
    so I'll quickly summarize basically a
  • 18:42 - 18:46
    hash function is you can think of it as
  • 18:44 - 18:48
    like this magical function that takes a
  • 18:46 - 18:51
    big piece of data and turns it into a
  • 18:48 - 18:55
    short string at a high level these are
  • 18:51 - 18:56
    used to or maybe that's like a
  • 18:55 - 18:57
    sufficient
  • 18:56 - 18:58
    clinician I won't go into too much more
  • 18:57 - 18:59
    detail here but you can ask me
  • 18:58 - 19:03
    afterwards if you're if you're curious
  • 18:59 - 19:05
    so basically they give you a way to name
  • 19:03 - 19:06
    a thing in a way that's kind of
  • 19:05 - 19:08
    deterministic based on the constants of
  • 19:06 - 19:10
    the thing it takes into thing as input
  • 19:08 - 19:13
    and gives you a short name for it and
  • 19:10 - 19:16
    then the opposite of stores load the way
  • 19:13 - 19:18
    we can load things from the store you
  • 19:16 - 19:29
    might have just guessed you can look
  • 19:18 - 19:30
    them up by their ID and this is just we
  • 19:29 - 19:36
    retrieve it from the object store by ID
  • 19:30 - 19:40
    and it gives us back the contents any
  • 19:36 - 19:42
    questions about this so far question
  • 19:40 - 19:43
    that's a good question what language is
  • 19:42 - 19:45
    it's all written in it's written in the
  • 19:43 - 19:48
    language I just made up so it's
  • 19:45 - 19:51
    pseudocode the get implementation itself
  • 19:48 - 19:55
    is a mix of C it's mostly C and then
  • 19:51 - 19:57
    some bash and Perl scripts I think any
  • 19:55 - 19:59
    other questions is this made-up language
  • 19:57 - 20:06
    clear enough or do I need to explain any
  • 19:59 - 20:09
    aspects of it great okay so blobs trees
  • 20:06 - 20:15
    and commits and get are unified in this
  • 20:09 - 20:16
    way they're all objects and also as you
  • 20:15 - 20:19
    might think given my description here
  • 20:16 - 20:21
    like it looks like commits contain a
  • 20:19 - 20:23
    whole bunch of other commits and contain
  • 20:21 - 20:25
    a snapshot and things like that in
  • 20:23 - 20:29
    practice it doesn't actually work that
  • 20:25 - 20:32
    way instead all these are pointers so a
  • 20:29 - 20:34
    commit will be able to reference a bunch
  • 20:32 - 20:36
    of parents by their IDs so this is
  • 20:34 - 20:39
    actually not an array of commits
  • 20:36 - 20:41
    themselves but IDs and similarly the
  • 20:39 - 20:43
    snapshot inside a commit is not the
  • 20:41 - 20:45
    actual tree object it's the ID of the
  • 20:43 - 20:46
    tree and so all these objects are kind
  • 20:45 - 20:49
    of stored on their own in this object
  • 20:46 - 20:51
    store and then all the references to
  • 20:49 - 20:54
    different objects are just by their ID
  • 20:51 - 20:56
    by their sha-1 hash does that make sense
  • 20:54 - 20:58
    you can almost in your head map it to
  • 20:56 - 21:00
    like these are objects in a programming
  • 20:58 - 21:02
    language like Java and then this is a
  • 21:00 - 21:04
    reference to a tree so it's like a
  • 21:02 - 21:06
    pointer and then that is your realm
  • 21:04 - 21:08
    maybe this naughty helps maybe it
  • 21:06 - 21:08
    doesn't
  • 21:09 - 21:21
    yeah yeah exactly so I'll just repeat
  • 21:20 - 21:21
    that for everybody to hear on the
  • 21:21 - 21:25
    microphone
  • 21:21 - 21:27
    this is gets on disk data store it's a
  • 21:25 - 21:37
    Content address store where objects are
  • 21:27 - 21:40
    addressed by their hash all right any
  • 21:37 - 21:46
    questions about that so far ok so now we
  • 21:40 - 21:48
    have a way of identifying we've unified
  • 21:46 - 21:50
    all the different types of objects into
  • 21:48 - 21:52
    one type of thing we call object and we
  • 21:50 - 21:54
    have a way of identifying objects by
  • 21:52 - 21:56
    their sha-1 hash what do these actual
  • 21:54 - 21:58
    sha-1 hashes look like well they're
  • 21:56 - 21:59
    hexadecimal strings that are 40
  • 21:58 - 22:03
    characters long
  • 21:59 - 22:06
    like sha-1 is a 160-bit hash and so one
  • 22:03 - 22:07
    of the actual IDs returned by that sha-1
  • 22:06 - 22:12
    function is going to be a really long
  • 22:07 - 22:13
    string and so given that we'll have ways
  • 22:12 - 22:15
    of identifying these different things
  • 22:13 - 22:20
    like this we'll have corresponding to it
  • 22:15 - 22:27
    an ID like for a 3-2 CEB or something
  • 22:20 - 22:30
    something so now we have a way of naming
  • 22:27 - 22:31
    everything in this commit graph but
  • 22:30 - 22:34
    these names are really inconvenient
  • 22:31 - 22:36
    because they're super long and they're
  • 22:34 - 22:39
    like text strings they're not meaningful
  • 22:36 - 22:41
    to humans in any way so it's solution to
  • 22:39 - 22:43
    this problem is one other thing so get
  • 22:41 - 22:46
    maintains a set of objects and then it
  • 22:43 - 22:49
    maintains a set of references what our
  • 22:46 - 22:54
    references here I'll erase this bit on
  • 22:49 - 22:54
    the left this parts pretty logical
  • 22:55 - 23:03
    that's the irony another time so
  • 22:57 - 23:03
    references all right here
  • 23:03 - 23:09
    so this is another piece of data that
  • 23:06 - 23:17
    get maintains internally references is a
  • 23:09 - 23:19
    map from string to string and you can
  • 23:17 - 23:23
    think of this as mapping human readable
  • 23:19 - 23:28
    names like I might have a name like fix
  • 23:23 - 23:31
    encoding bug fix - encoding - bug is a
  • 23:28 - 23:33
    human readable name and this would be
  • 23:31 - 23:36
    maps to like that long hexadecimal
  • 23:33 - 23:38
    string there and so with these
  • 23:36 - 23:41
    references and you can imagine how we
  • 23:38 - 23:44
    might have ways of creating new
  • 23:41 - 23:45
    references and updating references and
  • 23:44 - 23:48
    things like that
  • 23:45 - 23:51
    with this I can now refer to things in
  • 23:48 - 23:55
    my commit graph by name so I might have
  • 23:51 - 23:57
    the same be called like fix bug or I
  • 23:55 - 24:00
    might have a name for something over
  • 23:57 - 24:02
    here things like that and so yeah with
  • 24:00 - 24:04
    this skit can use human readable names
  • 24:02 - 24:06
    to refer to particular snapshots in the
  • 24:04 - 24:10
    history instead of these long
  • 24:06 - 24:14
    hexadecimal strings one other thing to
  • 24:10 - 24:17
    be aware of here is given gits design
  • 24:14 - 24:19
    for history this entire graph is
  • 24:17 - 24:21
    actually immutable you can add new stuff
  • 24:19 - 24:23
    to it but you can't actually manipulate
  • 24:21 - 24:26
    anything in here I won't go into the
  • 24:23 - 24:28
    details of exactly how or why but just
  • 24:26 - 24:30
    assume that that's the case however
  • 24:28 - 24:32
    references are immutable so as you're
  • 24:30 - 24:33
    updating the history like suppose you
  • 24:32 - 24:35
    keep working on this piece of software
  • 24:33 - 24:37
    you create a new commit so I'm
  • 24:35 - 24:38
    representing that by the circle this
  • 24:37 - 24:41
    points to the previous commit I can
  • 24:38 - 24:43
    actually have say my fixed bug reference
  • 24:41 - 24:48
    is pointing here I can update this
  • 24:43 - 24:51
    reference to now point over here however
  • 24:48 - 24:52
    I can't for example make this point over
  • 24:51 - 24:55
    here that's not even a meaningful thing
  • 24:52 - 24:57
    to say because this is just the hash of
  • 24:55 - 24:58
    this object to change this hash I'd need
  • 24:57 - 25:01
    to change the contents of the object
  • 24:58 - 25:01
    which doesn't really make sense
  • 25:03 - 25:06
    all right any questions about that so
  • 25:05 - 25:09
    far that's basically it forgets data
  • 25:06 - 25:10
    model and then we'll go into actually
  • 25:09 - 25:12
    interacting with get via the command
  • 25:10 - 25:14
    line and we'll see how git commands
  • 25:12 - 25:17
    correspond with manipulations of a graph
  • 25:14 - 25:22
    data structure so any questions about
  • 25:17 - 25:24
    modeling history as trees of trees and
  • 25:22 - 25:25
    blobs and then snapshots these things
  • 25:24 - 25:27
    called commits being chained together
  • 25:25 - 25:33
    and you have references that can point
  • 25:27 - 25:39
    to particular nodes in this graph cool
  • 25:33 - 25:42
    no questions so basically once we have
  • 25:39 - 25:44
    objects and references like that's
  • 25:42 - 25:47
    basically all there is to a git
  • 25:44 - 25:53
    repository those are the two pieces of
  • 25:47 - 25:53
    data that it stores and at a high level
  • 25:53 - 25:59
    all get command line commands are just
  • 25:57 - 26:12
    manipulations of either the references
  • 25:59 - 26:13
    data or the objects data okay so for the
  • 26:12 - 26:15
    rest of this lecture I'm going to go
  • 26:13 - 26:17
    through some git commands it's basically
  • 26:15 - 26:18
    going to be an interactive demo similar
  • 26:17 - 26:20
    to the vim lecture and then you can
  • 26:18 - 26:22
    refer to the notes for full information
  • 26:20 - 26:23
    on these commands look of course it's a
  • 26:22 - 26:28
    really powerful tool we can't cover
  • 26:23 - 26:30
    everything in what 20 minutes all right
  • 26:28 - 26:32
    so I'm going to go over to this folder
  • 26:30 - 26:34
    called playground and I'm going to make
  • 26:32 - 26:36
    a new directory called demo CD into demo
  • 26:34 - 26:38
    and this directory is going to represent
  • 26:36 - 26:40
    the top level of my project it's
  • 26:38 - 26:44
    currently empty because I just created
  • 26:40 - 26:46
    it if I want to turn this into a git
  • 26:44 - 26:49
    repository I use the git init command
  • 26:46 - 26:52
    get in it stands for git initialize and
  • 26:49 - 26:54
    we see that it says initialized empty
  • 26:52 - 26:58
    git repository in blah blah slash dot
  • 26:54 - 27:01
    git if I do LS I still see nothing but
  • 26:58 - 27:03
    if I do LS - a there's a hidden file in
  • 27:01 - 27:05
    this directory called dot git if I do LS
  • 27:03 - 27:08
    get there's a bunch of stuff in here
  • 27:05 - 27:09
    this is the directory on disk where it
  • 27:08 - 27:11
    gets stores all of its internal data
  • 27:09 - 27:13
    namely the objects and the references
  • 27:11 - 27:15
    and you actually see here objects and
  • 27:13 - 27:17
    refs as two directories in here and
  • 27:15 - 27:22
    all the repository data will be stored
  • 27:17 - 27:24
    underneath those two directories one
  • 27:22 - 27:25
    letter command to keep in mind as we're
  • 27:24 - 27:27
    going through these is something called
  • 27:25 - 27:29
    get help get help takes a sub command as
  • 27:27 - 27:31
    an argument it gives you some help on it
  • 27:29 - 27:34
    so if I do get help in it for example
  • 27:31 - 27:38
    it'll tell me about the git init command
  • 27:34 - 27:39
    so now there are some commands for
  • 27:38 - 27:41
    figuring out what's going on with a git
  • 27:39 - 27:44
    repository like git status at a high
  • 27:41 - 27:46
    level says what is going on right now
  • 27:44 - 27:48
    and we see here let's ignore the first
  • 27:46 - 27:50
    line for now the second line says no
  • 27:48 - 27:52
    commits yet that's because we just
  • 27:50 - 27:54
    initialized a fresh repository and so
  • 27:52 - 27:58
    there is no history yet I'm actually
  • 27:54 - 28:00
    going to does anybody still want this
  • 27:58 - 28:03
    are kind of clear this part of the board
  • 28:00 - 28:05
    I'm going to as we go along draw how the
  • 28:03 - 28:08
    underlying objects and references data
  • 28:05 - 28:10
    is changing when I type in certain git
  • 28:08 - 28:12
    commands so right now this picture or
  • 28:10 - 28:14
    lack of picture represents the current
  • 28:12 - 28:18
    state of our repository it's empty there
  • 28:14 - 28:20
    are no snapshots so let's fix that let's
  • 28:18 - 28:23
    add something to our history here we
  • 28:20 - 28:25
    have no files so let me just go ahead
  • 28:23 - 28:27
    and create a file hello.txt with the
  • 28:25 - 28:29
    content hello world normally you'd have
  • 28:27 - 28:33
    your source code with actually useful
  • 28:29 - 28:34
    stuff in it now what I want to do is I
  • 28:33 - 28:36
    want to take the current contents of
  • 28:34 - 28:38
    this directory and turn it into a new
  • 28:36 - 28:41
    snapshot to represent say the first
  • 28:38 - 28:43
    state my project was in you might
  • 28:41 - 28:44
    imagine an interface for doing this
  • 28:43 - 28:46
    where there is like a git snapshot
  • 28:44 - 28:48
    command or get something else command
  • 28:46 - 28:50
    which takes a snapshot of the entire
  • 28:48 - 28:51
    state of the current directory for a
  • 28:50 - 28:53
    number of reasons git doesn't have a
  • 28:51 - 28:55
    command that works exactly like that
  • 28:53 - 28:57
    because git wants to give you a little
  • 28:55 - 28:59
    bit of flexibility as to what changes to
  • 28:57 - 29:00
    include in the next snapshot you take
  • 28:59 - 29:02
    this is something that's kind of
  • 29:00 - 29:05
    confusing to beginners sometimes so I'll
  • 29:02 - 29:06
    try to explain it right now git has a
  • 29:05 - 29:10
    concept of something called a staging
  • 29:06 - 29:12
    area and at a high level it's where you
  • 29:10 - 29:16
    tell git what changes should be included
  • 29:12 - 29:18
    in the next snapshot you take if we do
  • 29:16 - 29:20
    get status here we'll see that git says
  • 29:18 - 29:23
    no commits yet like it said before and
  • 29:20 - 29:25
    it says untracked files hello Tex
  • 29:23 - 29:26
    so this is saying that get notices that
  • 29:25 - 29:28
    there's a new file in the current
  • 29:26 - 29:29
    directory but it is not going to be
  • 29:28 - 29:31
    included in the neck
  • 29:29 - 29:35
    snapshot gets kind of ignoring it for
  • 29:31 - 29:37
    now but if I do get ad hello text and if
  • 29:35 - 29:40
    I do get status again it says now
  • 29:37 - 29:42
    changes to be committed new file
  • 29:40 - 29:44
    hello.txt and so now if I do the get
  • 29:42 - 29:46
    snapshot command which is actually get
  • 29:44 - 29:48
    commit which creates a new one of those
  • 29:46 - 29:50
    circles I drone the board over there
  • 29:48 - 29:53
    this file will be included in that
  • 29:50 - 29:56
    snapshot I'm I take so let me go ahead
  • 29:53 - 29:58
    and run git commit what this does is it
  • 29:56 - 29:59
    pops up my text editor and it lets me
  • 29:58 - 30:01
    type in a message that will be
  • 29:59 - 30:03
    associated with this commit and it's
  • 30:01 - 30:04
    really good to write high-quality commit
  • 30:03 - 30:05
    messages because then later when you're
  • 30:04 - 30:07
    looking back at your products version
  • 30:05 - 30:12
    history you'll know why you made certain
  • 30:07 - 30:14
    changes I'm going to add this relatively
  • 30:12 - 30:16
    useless commit message but we have a
  • 30:14 - 30:18
    link in the lecture notes for a guide on
  • 30:16 - 30:21
    how to write high-quality commit
  • 30:18 - 30:24
    messages so now that I've done that get
  • 30:21 - 30:27
    prints out some output master ignore
  • 30:24 - 30:29
    that bit for now this thing is the hash
  • 30:27 - 30:33
    of the commit I just created so now I
  • 30:29 - 30:35
    have in my history a single node this
  • 30:33 - 30:38
    has in it a tree that has a single blob
  • 30:35 - 30:41
    a single file hello.txt with the
  • 30:38 - 30:46
    contents hello world and then this has
  • 30:41 - 30:48
    the sha-1 hash for 2fb
  • 30:46 - 30:49
    something something something it's
  • 30:48 - 30:53
    actually truncated in the get interface
  • 30:49 - 30:55
    as well this is just printing out my
  • 30:53 - 30:57
    commit message again and it says as a
  • 30:55 - 31:01
    reminder I just added hello dot text and
  • 30:57 - 31:02
    so now if I use the git log command so
  • 31:01 - 31:05
    the git log commit is really useful in
  • 31:02 - 31:10
    that it helps you visualize the history
  • 31:05 - 31:10
    the the commit graph if I do question
  • 31:16 - 31:20
    that's a great question so the question
  • 31:19 - 31:23
    is what exactly does this hash
  • 31:20 - 31:26
    correspond to so this is the hash of the
  • 31:23 - 31:29
    commit the commit contains inside of it
  • 31:26 - 31:31
    the hash of the tree along with whatever
  • 31:29 - 31:36
    other information so I can actually use
  • 31:31 - 31:38
    get cat file - P this number this is
  • 31:36 - 31:41
    kind of like a get internals command
  • 31:38 - 31:42
    that will print out the contents of this
  • 31:41 - 31:42
    commit so you can see this kind of maps
  • 31:42 - 31:44
    to
  • 31:42 - 31:46
    data structure I drew on the board over
  • 31:44 - 31:48
    there so this commit has inside of it
  • 31:46 - 31:49
    this tree and then I'm the author and
  • 31:48 - 31:51
    this is the commit message and so on and
  • 31:49 - 31:53
    I can continue digging down here so you
  • 31:51 - 31:56
    can take this hash of this tree and do
  • 31:53 - 31:59
    get cat file - P this hash here it says
  • 31:56 - 32:03
    that this tree has inside of it a single
  • 31:59 - 32:06
    entry hello text and that file has it's
  • 32:03 - 32:09
    a blob and it has this hash I can do get
  • 32:06 - 32:12
    cat file - P this thing and it will show
  • 32:09 - 32:13
    me the actual contents of that file so
  • 32:12 - 32:16
    these are like internal git commands to
  • 32:13 - 32:23
    explore objects in the object store
  • 32:16 - 32:25
    question that's a great question so the
  • 32:23 - 32:27
    question is why did I have to use get
  • 32:25 - 32:29
    add why can't you just commit all
  • 32:27 - 32:30
    changes and the answer is well there
  • 32:29 - 32:34
    kind of is a way to commit all changes
  • 32:30 - 32:36
    if you do get commit - a this commits
  • 32:34 - 32:38
    all the changes that were made to files
  • 32:36 - 32:39
    that are already being tracked by git so
  • 32:38 - 32:41
    anything that was included in the
  • 32:39 - 32:44
    previous snapshot but has been modified
  • 32:41 - 32:47
    since then it doesn't include new things
  • 32:44 - 32:49
    there's also variants of git add like if
  • 32:47 - 32:51
    you do get add colon slash this will add
  • 32:49 - 32:53
    everything in the top from the top level
  • 32:51 - 32:55
    down of your repository but at a higher
  • 32:53 - 32:57
    level the reason we have this separation
  • 32:55 - 32:59
    between git add and git commit and why
  • 32:57 - 33:01
    get come it doesn't just snapshot the
  • 32:59 - 33:02
    entire directory is that they're often
  • 33:01 - 33:04
    situations where you don't want to
  • 33:02 - 33:06
    include everything in the current
  • 33:04 - 33:08
    snapshot like here's a couple examples
  • 33:06 - 33:10
    one is that I might be packing on my
  • 33:08 - 33:12
    project and I go ahead and implement two
  • 33:10 - 33:14
    features maybe I don't want to have a
  • 33:12 - 33:16
    single snapshot that comes after this
  • 33:14 - 33:18
    one that's like I implemented feature a
  • 33:16 - 33:19
    and feature B maybe I want to create two
  • 33:18 - 33:21
    separate nodes in the history so that it
  • 33:19 - 33:23
    looks like first I implemented feature a
  • 33:21 - 33:24
    and then after that I implemented
  • 33:23 - 33:26
    feature B so I have one snapshot that
  • 33:24 - 33:29
    only includes a and then the next one
  • 33:26 - 33:31
    includes both a and B git add is a tool
  • 33:29 - 33:32
    and like the staging area in general is
  • 33:31 - 33:33
    a tool that will allow me to do that
  • 33:32 - 33:36
    sort of thing
  • 33:33 - 33:38
    another example is suppose I'm working
  • 33:36 - 33:39
    on a bug fix and I have printf
  • 33:38 - 33:41
    statements I've put all over my code and
  • 33:39 - 33:42
    then finally I find the bug and there's
  • 33:41 - 33:43
    a plus one somewhere where there
  • 33:42 - 33:45
    shouldn't be a plus one so go fix that
  • 33:43 - 33:46
    and then I want to take a new snapshot
  • 33:45 - 33:48
    right with my fix
  • 33:46 - 33:50
    but the snapshot probably should include
  • 33:48 - 33:52
    all of my print statements it just needs
  • 33:50 - 33:54
    to include the fix of removing that plus
  • 33:52 - 33:55
    one so one way I could solve that issue
  • 33:54 - 33:57
    is I can go in
  • 33:55 - 33:59
    annually remove all the print statements
  • 33:57 - 34:01
    but it has a much better way of doing
  • 33:59 - 34:03
    that there's actually a way to specify
  • 34:01 - 34:06
    that I only want to add the change of
  • 34:03 - 34:08
    removing that plus one then I can commit
  • 34:06 - 34:09
    that take the new snapshot and then I
  • 34:08 - 34:11
    can throw away all the other changes
  • 34:09 - 34:12
    there are commands for doing that and
  • 34:11 - 34:14
    some of them are linked in the lecture
  • 34:12 - 34:16
    notes so those are two ways in which you
  • 34:14 - 34:18
    can use the staging area to help you and
  • 34:16 - 34:25
    why there isn't just like a snapshot
  • 34:18 - 34:26
    everything command yeah so mm-hmm yeah
  • 34:25 - 34:28
    John John points out the yeah yet
  • 34:26 - 34:29
    another example is you might have log
  • 34:28 - 34:31
    files in your current directory that
  • 34:29 - 34:33
    your program runs when you run it and
  • 34:31 - 34:35
    you probably don't want to include those
  • 34:33 - 34:36
    when you take a snapshot there's
  • 34:35 - 34:38
    probably other things like if you
  • 34:36 - 34:40
    compile your project you end up with a
  • 34:38 - 34:41
    bunch of dotto and like elf files you
  • 34:40 - 34:47
    probably don't want those to be part of
  • 34:41 - 34:50
    your history so going back to what I was
  • 34:47 - 34:51
    showing you before I'm going to clear
  • 34:50 - 34:54
    the terminal screen and then show you
  • 34:51 - 34:55
    the git log command so get logged lets
  • 34:54 - 34:58
    you visualize the version history and
  • 34:55 - 35:00
    this is an incredibly helpful command by
  • 34:58 - 35:03
    default git log shows you a flattened
  • 35:00 - 35:04
    version of the version history so even
  • 35:03 - 35:05
    though the version history is a graph
  • 35:04 - 35:07
    this will linearize it and just show
  • 35:05 - 35:09
    things in order i personally find that
  • 35:07 - 35:11
    confusing so I almost never use git log
  • 35:09 - 35:13
    and instead get log takes some arguments
  • 35:11 - 35:19
    that actually show the history as a
  • 35:13 - 35:20
    graph so you can treat this as a magic
  • 35:19 - 35:22
    incantation for now and you can read the
  • 35:20 - 35:23
    documentation if you want to figure out
  • 35:22 - 35:25
    exactly what each of those flags does
  • 35:23 - 35:28
    but for now this doesn't look all that
  • 35:25 - 35:29
    different because we only have one node
  • 35:28 - 35:31
    in our graph so visualizing it as a
  • 35:29 - 35:34
    flattened thing versus a graph doesn't
  • 35:31 - 35:37
    look all that different let me go ahead
  • 35:34 - 35:39
    and create a new snapshot and then we
  • 35:37 - 35:44
    can run this command again and then see
  • 35:39 - 35:48
    exactly what it does so I will put
  • 35:44 - 35:50
    another line into hello dot text and so
  • 35:48 - 35:53
    if I cat hello dot text it has the thing
  • 35:50 - 35:55
    it had before plus this I can do get
  • 35:53 - 35:57
    commit and notice this doesn't do
  • 35:55 - 36:00
    anything it just says no stained state
  • 35:57 - 36:02
    no changes staged for commit why is that
  • 36:00 - 36:04
    it's because I didn't add this to the
  • 36:02 - 36:04
    staging area I didn't tell yet but like
  • 36:04 - 36:06
    this is something that should be
  • 36:04 - 36:11
    included in the next snap
  • 36:06 - 36:13
    so if I do get ad hallo text get status
  • 36:11 - 36:15
    it says okay this change is ready to be
  • 36:13 - 36:20
    committed this modification to this file
  • 36:15 - 36:24
    and now I can do git commit I'm gonna
  • 36:20 - 36:27
    put in a useless commit message and the
  • 36:24 - 36:29
    new changes have been made and so now my
  • 36:27 - 36:31
    history has another note in it and then
  • 36:29 - 36:35
    this note has some hash that's shown on
  • 36:31 - 36:37
    the screen and now if I rerun that
  • 36:35 - 36:40
    command from earlier the git log with
  • 36:37 - 36:42
    all these arguments it actually starts
  • 36:40 - 36:45
    looking more like a graph here notice
  • 36:42 - 36:47
    that this is like that graph turned this
  • 36:45 - 36:49
    way the more recent so it's shown
  • 36:47 - 36:54
    vertically not horizontally and the more
  • 36:49 - 36:56
    recent commits are shown at the top this
  • 36:54 - 36:58
    is showing one commit it shows as commit
  • 36:56 - 37:01
    hash shows a bunch of metadata including
  • 36:58 - 37:03
    the commit message and then this is the
  • 37:01 - 37:05
    part I want to talk about next so
  • 37:03 - 37:06
    remember we talked about objects like
  • 37:05 - 37:08
    the actual contents of your repository
  • 37:06 - 37:10
    and then we talked about references ways
  • 37:08 - 37:15
    of naming things in the repository with
  • 37:10 - 37:16
    human readable names so master is one
  • 37:15 - 37:19
    reference that's created by default when
  • 37:16 - 37:21
    you initialize it get repository and by
  • 37:19 - 37:22
    convention it generally refers to like
  • 37:21 - 37:25
    the main branch of development in your
  • 37:22 - 37:27
    code so master will represent like the
  • 37:25 - 37:30
    most up-to-date version of your project
  • 37:27 - 37:32
    so here you can think of master as a
  • 37:30 - 37:34
    pointer to this commit and as we add
  • 37:32 - 37:37
    more commits this pointer will be
  • 37:34 - 37:39
    mutated to point to later commits then
  • 37:37 - 37:41
    we also see here head this is a special
  • 37:39 - 37:43
    reference and get it's a reference like
  • 37:41 - 37:46
    master but it's special in some way and
  • 37:43 - 37:50
    head basically is used to refer to where
  • 37:46 - 37:55
    you are currently looking right now any
  • 37:50 - 37:55
    questions so far yeah question
  • 38:04 - 38:09
    that's an excellent question so the
  • 38:06 - 38:10
    question is work with github before and
  • 38:09 - 38:14
    you have to create an account to do that
  • 38:10 - 38:16
    how does github relate to get and the
  • 38:14 - 38:20
    answer to that question is github is a
  • 38:16 - 38:22
    repository host for get so you can
  • 38:20 - 38:24
    create an account on github and store a
  • 38:22 - 38:26
    git repository there and use that to
  • 38:24 - 38:28
    collaborate with other people but git as
  • 38:26 - 38:30
    a command-line tool is just independent
  • 38:28 - 38:31
    from github so you don't have to use
  • 38:30 - 38:33
    github to use git you don't have to use
  • 38:31 - 38:34
    github declare it with get either like
  • 38:33 - 38:37
    there are other providers of git
  • 38:34 - 38:39
    repositories like bitbucket or get lab
  • 38:37 - 38:42
    or things like that and so yeah github
  • 38:39 - 39:05
    is a host for github repositories any
  • 38:42 - 39:07
    other questions yeah so the question is
  • 39:05 - 39:09
    if you want this repository to end up on
  • 39:07 - 39:11
    github how do you do that yeah there's a
  • 39:09 - 39:13
    separate set of commands for doing that
  • 39:11 - 39:16
    there's a so that concept of having your
  • 39:13 - 39:18
    local copy of version history interact
  • 39:16 - 39:19
    with another copy so the other copy is
  • 39:18 - 39:20
    called a remote and then their set of
  • 39:19 - 39:22
    commands for interacting with git
  • 39:20 - 39:24
    remotes and sending data from your
  • 39:22 - 39:27
    remote or from your copy to get remotes
  • 39:24 - 39:29
    and getting data from git remotes into
  • 39:27 - 39:31
    your local copy and we'll cover that
  • 39:29 - 39:32
    later in this lecture or maybe in the
  • 39:31 - 39:33
    lecture notes Ron might make a
  • 39:32 - 39:40
    supplemental video to go along with this
  • 39:33 - 39:43
    lecture any other questions okay a
  • 39:40 - 39:45
    couple other basic commands to show you
  • 39:43 - 39:46
    so so far I've shown you a version
  • 39:45 - 39:49
    history and we've taken a file and
  • 39:46 - 39:51
    modified it but we haven't really made
  • 39:49 - 39:53
    use of the history in any way besides
  • 39:51 - 39:55
    reading the messages so one useful git
  • 39:53 - 39:57
    command is something called git checkout
  • 39:55 - 39:58
    and this is a kind of wacky command it
  • 39:57 - 39:59
    lets you do a bunch of different things
  • 39:58 - 40:01
    but one thing it lets you do is move
  • 39:59 - 40:03
    around in your version history so one
  • 40:01 - 40:05
    thing I can do is give get checkout the
  • 40:03 - 40:07
    commit hash of a previous commit and I
  • 40:05 - 40:08
    don't need to type the whole thing I can
  • 40:07 - 40:10
    give it a prefix and it's
  • 40:08 - 40:12
    to figure out what I'm talking about and
  • 40:10 - 40:15
    what this will do is it will change the
  • 40:12 - 40:19
    state of my working directory to how it
  • 40:15 - 40:21
    was at that commit so here if I do cat
  • 40:19 - 40:23
    hello text recall that I had only one
  • 40:21 - 40:26
    line in here before at the first commit
  • 40:23 - 40:28
    and later I added that second line now
  • 40:26 - 40:30
    if I do that get logged command and this
  • 40:28 - 40:32
    command is super helpful like it shows
  • 40:30 - 40:34
    you all the things if I do this command
  • 40:32 - 40:36
    notice that this output looks a little
  • 40:34 - 40:38
    bit different than before like my actual
  • 40:36 - 40:40
    history contents the commits themselves
  • 40:38 - 40:42
    in the way they relate to each other and
  • 40:40 - 40:45
    all that have not changed but the
  • 40:42 - 40:47
    references have so notice that head is
  • 40:45 - 40:48
    down here even the master is still up
  • 40:47 - 40:51
    here so at high level what this is
  • 40:48 - 40:53
    telling me is this is what I'm looking
  • 40:51 - 40:56
    at right now if I want to go back here I
  • 40:53 - 40:57
    could type git checkout and this commit
  • 40:56 - 40:59
    hash
  • 40:57 - 41:00
    does anybody know a different thing I
  • 40:59 - 41:03
    could type here instead of this long
  • 41:00 - 41:06
    hash in order to go back to this commit
  • 41:03 - 41:09
    yeah you can give it the name of this is
  • 41:06 - 41:10
    a branch colored in green here and it
  • 41:09 - 41:12
    refers to this commit so I can give it
  • 41:10 - 41:14
    the short name or the human readable
  • 41:12 - 41:18
    name instead and now if I do cat hello
  • 41:14 - 41:18
    text notice that it has that second line
  • 41:23 - 41:26
    [Music]
  • 41:31 - 41:43
    yeah yeah so to repeat that git checkout
  • 41:41 - 41:46
    actually changes the contents of your
  • 41:43 - 41:47
    working directory and so in that way it
  • 41:46 - 41:50
    can be a somewhat dangerous command if
  • 41:47 - 41:55
    you misuse it for example you can see if
  • 41:50 - 41:56
    I modify hello text and then try that
  • 41:55 - 41:58
    get checkout command from earlier
  • 41:56 - 42:01
    actually notice here that it says error
  • 41:58 - 42:02
    it says there's a file that's been
  • 42:01 - 42:04
    modified and the git checkout would
  • 42:02 - 42:06
    destroy your modification you probably
  • 42:04 - 42:07
    want to do something about that but
  • 42:06 - 42:09
    there are flags like for example get
  • 42:07 - 42:11
    checkout - eff does this forcibly and
  • 42:09 - 42:13
    now it's throwing away my changes so
  • 42:11 - 42:14
    yeah get checkout has the potential to
  • 42:13 - 42:16
    well it certainly does modify things in
  • 42:14 - 42:17
    your working directory and it can
  • 42:16 - 42:22
    actually destroy changes if you're not
  • 42:17 - 42:22
    careful question
  • 42:24 - 42:29
    exactly yeah this is exactly what I want
  • 42:27 - 42:31
    you to be thinking about how these like
  • 42:29 - 42:34
    the crazy get interface commands
  • 42:31 - 42:36
    correspond to mutations to this graph
  • 42:34 - 42:37
    and mutations to the reference or like
  • 42:36 - 42:41
    additions to the graph in mutations to
  • 42:37 - 42:44
    the references map so yeah exactly
  • 42:41 - 42:45
    get checkout moves the head pointer and
  • 42:44 - 42:48
    then also mutates the contents of your
  • 42:45 - 42:50
    working directory with the contents that
  • 42:48 - 42:54
    the head pointer now points to of course
  • 42:50 - 43:01
    my name for that commit any other
  • 42:54 - 43:03
    questions all right so one other basic
  • 43:01 - 43:06
    command I want to show you is the git
  • 43:03 - 43:09
    diff command so I'm going to modify this
  • 43:06 - 43:11
    file and put some changes in it the git
  • 43:09 - 43:14
    diff command can show you what's changed
  • 43:11 - 43:15
    since the last snapshot it's just
  • 43:14 - 43:18
    helpful for like knowing what's going on
  • 43:15 - 43:23
    with your project git diff can also take
  • 43:18 - 43:26
    extra arguments like you can do git diff
  • 43:23 - 43:28
    and say compute a diff not with respect
  • 43:26 - 43:30
    to the last snapshot the last commit but
  • 43:28 - 43:32
    with respect to this and say ok two
  • 43:30 - 43:35
    lines have been added since this point
  • 43:32 - 43:35
    to hello dot text
  • 43:41 - 43:53
    question so your the question is what
  • 43:51 - 43:56
    does this command do without this extra
  • 43:53 - 44:00
    argument here that's a good question so
  • 43:56 - 44:05
    what this does is it computes a DIF with
  • 44:00 - 44:07
    respect to head and looking at my get
  • 44:05 - 44:09
    log hat is pointing to here so it's
  • 44:07 - 44:11
    doing a get diff with respect to this
  • 44:09 - 44:12
    commit and you can actually specify that
  • 44:11 - 44:32
    explicitly you can do get diff had
  • 44:12 - 44:34
    hollow text okay yes uh-huh
  • 44:32 - 44:37
    so that's a good question it's like how
  • 44:34 - 44:38
    can hello dot text be different than
  • 44:37 - 44:41
    head because head refers to where you
  • 44:38 - 44:45
    currently are so to clarify head refers
  • 44:41 - 44:51
    to the last snapshot so like in my
  • 44:45 - 44:54
    picture here had and master are both
  • 44:51 - 44:56
    here and the current working directory
  • 44:54 - 44:57
    is kind of independent of this like
  • 44:56 - 44:59
    you're going to delete all the files in
  • 44:57 - 45:00
    here it doesn't change the history graph
  • 44:59 - 45:02
    or the references and so yeah you can
  • 45:00 - 45:03
    have differences between here and here
  • 45:02 - 45:05
    and at a high level this is how you work
  • 45:03 - 45:07
    on a project like you make some changes
  • 45:05 - 45:09
    here you get add them to stage them and
  • 45:07 - 45:13
    then you get commit and that creates a
  • 45:09 - 45:18
    new snapshot here good question
  • 45:13 - 45:18
    any other questions yep
  • 45:26 - 45:30
    so the question is does get actually
  • 45:28 - 45:31
    save all this stuff kind of in the
  • 45:30 - 45:34
    obvious way or is it doing something
  • 45:31 - 45:36
    fancier the answer is is it is doing
  • 45:34 - 45:38
    something a little bit fancier but you
  • 45:36 - 45:40
    can it has an interface that lets you
  • 45:38 - 45:42
    think of it like it stored that way in
  • 45:40 - 45:45
    practice get uses Delta compression it
  • 45:42 - 45:46
    also does some other stuff but yeah the
  • 45:45 - 45:58
    on disk representation is actually
  • 45:46 - 46:00
    reasonably efficient question yeah
  • 45:58 - 46:03
    that's a good question so the question
  • 46:00 - 46:05
    is here we were comparing the current
  • 46:03 - 46:07
    working directory with a particular
  • 46:05 - 46:09
    snapshot in the past can we compare two
  • 46:07 - 46:11
    snapshots with each other like at two
  • 46:09 - 46:12
    different points in the history and yeah
  • 46:11 - 46:14
    I get diff can take yet another argument
  • 46:12 - 46:18
    here so I can for example compare head
  • 46:14 - 46:21
    with it did in the wrong order I can
  • 46:18 - 46:24
    compare what change from here to head in
  • 46:21 - 46:27
    hello text and it shows me that I added
  • 46:24 - 46:30
    the second line in there any other
  • 46:27 - 46:30
    questions
  • 46:41 - 46:44
    yeah so the question is you're working
  • 46:43 - 46:46
    on a shared project in a Dropbox folder
  • 46:44 - 46:49
    and anyone a migrate to get does it make
  • 46:46 - 46:52
    sense to turn the Dropbox folder into a
  • 46:49 - 46:53
    git repo do not use get inside dropbox
  • 46:52 - 46:55
    dropbox will corrupt your gate repo
  • 46:53 - 46:57
    there are good solutions to doing that
  • 46:55 - 46:58
    one is just use github otherwise I talk
  • 46:57 - 47:04
    to me after class and there ways of
  • 46:58 - 47:06
    using Dropbox as I get remote safely any
  • 47:04 - 47:06
    other questions
  • 47:07 - 47:11
    next we're going to talk about branching
  • 47:09 - 47:13
    and merging which is another powerful
  • 47:11 - 47:15
    feature of get that you almost certainly
  • 47:13 - 47:16
    use both when working on your own
  • 47:15 - 47:20
    projects and when collaborating with
  • 47:16 - 47:22
    others for this series of demos we're
  • 47:20 - 47:25
    going to rather than work with a simple
  • 47:22 - 47:27
    text file actually write a simple
  • 47:25 - 47:28
    computer program because it'll better
  • 47:27 - 47:30
    illustrate the concepts of branching and
  • 47:28 - 47:33
    merging and as we go through this
  • 47:30 - 47:35
    demonstration we'll keep in mind how the
  • 47:33 - 47:37
    get interface commands connect to the
  • 47:35 - 47:40
    underlying data model connect to objects
  • 47:37 - 47:44
    and references and how these commands
  • 47:40 - 47:46
    modify those two data structures let me
  • 47:44 - 47:48
    do a get status to see the current state
  • 47:46 - 47:50
    of my repository here I've modified
  • 47:48 - 47:52
    hello text I actually don't really care
  • 47:50 - 47:55
    about this modification anymore this is
  • 47:52 - 47:58
    some random file if I do get check out
  • 47:55 - 48:00
    folio text this is another different use
  • 47:58 - 48:02
    of the check out command which basically
  • 48:00 - 48:05
    throws away the changes that I've made
  • 48:02 - 48:07
    in the working directory and sets the
  • 48:05 - 48:10
    contents of hello text back to the way
  • 48:07 - 48:12
    it was in the snapshot that head points
  • 48:10 - 48:15
    to if I like it get logged - - all -
  • 48:12 - 48:18
    graft - - decorate it'll show me that
  • 48:15 - 48:21
    here I added the initial attacks and it
  • 48:18 - 48:23
    added that single line here and so now
  • 48:21 - 48:26
    whole text doesn't have that third line
  • 48:23 - 48:29
    I'd added it just has the original -
  • 48:26 - 48:30
    next time we should write a very simple
  • 48:29 - 48:34
    program we'll call this program and a
  • 48:30 - 48:36
    mold pie and let me just go ahead and
  • 48:34 - 48:44
    write a program that it prints a little
  • 48:36 - 48:44
    bit of output when I run it let's see
  • 48:46 - 48:50
    [Applause]
  • 48:48 - 48:52
    so when I run this program it runs main
  • 48:50 - 48:54
    mean calls default and then let me go
  • 48:52 - 48:57
    right ahead go ahead and define default
  • 48:54 - 48:59
    and default is going it's just going to
  • 48:57 - 49:02
    print hello so this is a program that
  • 48:59 - 49:03
    greets its user and so if I run animal
  • 49:02 - 49:05
    dot pi I'll see that it just prints
  • 49:03 - 49:08
    hello so that'll be our starting point
  • 49:05 - 49:12
    if I do get status it shows me that
  • 49:08 - 49:14
    animal dot hi is an untracked file to
  • 49:12 - 49:17
    begin with i want this to be part of my
  • 49:14 - 49:19
    part of the snapshot so i'm going to get
  • 49:17 - 49:24
    add animal dot hi to add it to the
  • 49:19 - 49:24
    staging area and do then do a git commit
  • 49:25 - 49:29
    here I'm going to write yet another
  • 49:27 - 49:30
    useless commit message don't actually
  • 49:29 - 49:33
    write commit messages like this in real
  • 49:30 - 49:35
    projects but for now this is fine so now
  • 49:33 - 49:38
    I have this basic animal dot pi and if I
  • 49:35 - 49:41
    look at my get history now I have this
  • 49:38 - 49:44
    latest snapshot this is the commit hash
  • 49:41 - 49:46
    and this is where the master branch is
  • 49:44 - 49:49
    pointing now we're actually way to
  • 49:46 - 49:52
    demonstrate how to use git branches to
  • 49:49 - 49:54
    have parallel lines of development they
  • 49:52 - 49:55
    get branch command or the branch
  • 49:54 - 49:57
    sub-command is used to access
  • 49:55 - 50:00
    functionality related to branching just
  • 49:57 - 50:01
    running git branch by itself lists all
  • 50:00 - 50:03
    the branches that are present in the
  • 50:01 - 50:06
    local repository it can also take an
  • 50:03 - 50:09
    extra argument - V V to be extra verbose
  • 50:06 - 50:11
    and print some extra information if we
  • 50:09 - 50:13
    do get branch and then specify the name
  • 50:11 - 50:15
    for a new branch git will create a new
  • 50:13 - 50:17
    branch which is just a reference that
  • 50:15 - 50:18
    points the same place where we're
  • 50:17 - 50:22
    currently looking so now there's a new
  • 50:18 - 50:23
    reference called cat reference in this
  • 50:22 - 50:25
    case is the same as branch there's a new
  • 50:23 - 50:27
    branch called cat which points to
  • 50:25 - 50:30
    wherever head was pointing if I look at
  • 50:27 - 50:32
    the git log again I'll see that here had
  • 50:30 - 50:34
    points to master masters over here and
  • 50:32 - 50:36
    this is also where the cat branches so
  • 50:34 - 50:40
    now I have two branches two references
  • 50:36 - 50:41
    that resolve to the same commit get is
  • 50:40 - 50:43
    actually aware of not only which
  • 50:41 - 50:44
    snapshot in the history are currently
  • 50:43 - 50:47
    looking at so had points to this commit
  • 50:44 - 50:49
    but it's also aware of had kind of being
  • 50:47 - 50:51
    associated with a with a branch so here
  • 50:49 - 50:52
    head is associated with master and it's
  • 50:51 - 50:55
    the case that if I create a new snapshot
  • 50:52 - 50:58
    if I type git commit at this point the
  • 50:55 - 51:00
    next snapshot will be created and
  • 50:58 - 51:02
    I'll point to that new snapshot master
  • 51:00 - 51:06
    will be updated along with head if I do
  • 51:02 - 51:08
    get checkout cat what this does is it
  • 51:06 - 51:09
    switches to the branch cat it replaces
  • 51:08 - 51:11
    the contents of the working directory
  • 51:09 - 51:13
    without with whatever cats pointing to
  • 51:11 - 51:15
    which in this case is the same as the
  • 51:13 - 51:18
    contents before but now if I look at the
  • 51:15 - 51:20
    git log again now I have head point to
  • 51:18 - 51:22
    cat instead of master and then master
  • 51:20 - 51:25
    also points to the same place the same
  • 51:22 - 51:27
    underlying commit and now at this point
  • 51:25 - 51:29
    if I make changes to my current working
  • 51:27 - 51:32
    directory and make a new commit the cat
  • 51:29 - 51:33
    branch the cat pointer will be updated
  • 51:32 - 51:34
    to point than you commit where as master
  • 51:33 - 51:37
    will continue pointing wherever it
  • 51:34 - 51:40
    pointed before so let me go ahead and
  • 51:37 - 51:42
    modify animal PI to add some cat related
  • 51:40 - 51:46
    functionality so I'm going to say that
  • 51:42 - 51:47
    if sISTAR V one is cat then run the cat
  • 51:46 - 51:49
    function otherwise run the default
  • 51:47 - 51:53
    function and then let me go ahead and
  • 51:49 - 51:55
    import define the cat function so cats
  • 51:53 - 51:59
    don't say hello them you know so cat
  • 51:55 - 52:01
    prints meow straightforward enough so
  • 51:59 - 52:04
    now if I run animal dot PI and give it
  • 52:01 - 52:05
    the cat argument it says meow if I give
  • 52:04 - 52:08
    it some other argument it defaults back
  • 52:05 - 52:10
    to the hello all right so simple change
  • 52:08 - 52:11
    I made if I do a get status that says
  • 52:10 - 52:14
    that animal that PI has been modified
  • 52:11 - 52:15
    Farren get diff it'll show me what's
  • 52:14 - 52:17
    changed since the last commit
  • 52:15 - 52:19
    so here I've added this cat function
  • 52:17 - 52:22
    highlighted in green then also change
  • 52:19 - 52:26
    the main function a little bit now here
  • 52:22 - 52:30
    if I do get add animal dot I get commit
  • 52:26 - 52:32
    I mean actually you write a slightly
  • 52:30 - 52:35
    more useful commit message this time I'm
  • 52:32 - 52:38
    going to add cat functionality and now
  • 52:35 - 52:40
    if I look at the git log I see a little
  • 52:38 - 52:41
    more stuff I'm going to show you one
  • 52:40 - 52:45
    more argument to this get logged command
  • 52:41 - 52:48
    there's an argument - - one line one
  • 52:45 - 52:49
    line spelled correctly which shows a
  • 52:48 - 52:52
    more compact representation of the graph
  • 52:49 - 52:53
    so sould be a more useful thing to use
  • 52:52 - 52:55
    because we're super zoomed into the
  • 52:53 - 52:58
    screen and there isn't that much space
  • 52:55 - 52:59
    to show a long commit history so here we
  • 52:58 - 53:02
    see the sequence of commits is still
  • 52:59 - 53:04
    linear and we have master still pointing
  • 53:02 - 53:06
    wherever it pointed before where we just
  • 53:04 - 53:08
    had the basic underlying animal top high
  • 53:06 - 53:10
    functionality but now we have this cat
  • 53:08 - 53:14
    branch which adds the cat functionality
  • 53:10 - 53:17
    we could for example get checkout master
  • 53:14 - 53:19
    to go back to the master branch and then
  • 53:17 - 53:21
    here if we look at animal dot pie it
  • 53:19 - 53:23
    doesn't have the cat functionality
  • 53:21 - 53:25
    anymore if we look at the git log we'll
  • 53:23 - 53:26
    see that head is pointing to master so
  • 53:25 - 53:29
    so we can jump back and forth between
  • 53:26 - 53:30
    parallel lines of development so now
  • 53:29 - 53:32
    that we have the cat functionality
  • 53:30 - 53:33
    suppose that we want to work on adding
  • 53:32 - 53:36
    dog functionality in parallel and
  • 53:33 - 53:37
    suppose that in this case like the cat
  • 53:36 - 53:39
    functionality is under development or
  • 53:37 - 53:40
    maybe somebody else is working on it so
  • 53:39 - 53:42
    we just want to start from the base
  • 53:40 - 53:45
    master commit and build the dog
  • 53:42 - 53:46
    functionality starting from there so now
  • 53:45 - 53:48
    what do I want to do I want to create a
  • 53:46 - 53:49
    new branch dog for adding the dog
  • 53:48 - 53:52
    related functionality and I'll
  • 53:49 - 53:54
    eventually merge it in later so I can
  • 53:52 - 53:57
    use the git branch dog command followed
  • 53:54 - 53:59
    by the git checkout dog command to
  • 53:57 - 54:00
    create a new dog branch and then check
  • 53:59 - 54:04
    it out there's actually a short form for
  • 54:00 - 54:07
    this get checkout - b-dawg so this does
  • 54:04 - 54:10
    get branch dog get checkout dog and now
  • 54:07 - 54:11
    if I look at my graph I have cat where
  • 54:10 - 54:13
    it was before master where it was before
  • 54:11 - 54:16
    but now head instead of pointing to
  • 54:13 - 54:18
    master as it did before now head points
  • 54:16 - 54:20
    to this newly created dog reference
  • 54:18 - 54:23
    which is also at the same commit so at
  • 54:20 - 54:25
    this base commit and now I'll go ahead
  • 54:23 - 54:29
    and add my dog functionality so let me
  • 54:25 - 54:32
    go and define my dog function dogs don't
  • 54:29 - 54:34
    say hello they say woof and then I'll
  • 54:32 - 54:36
    add some similar functionality here to
  • 54:34 - 54:39
    decide whether to run default or dog so
  • 54:36 - 54:42
    if the first argument is dog then I want
  • 54:39 - 54:45
    to run the dog function otherwise whoops
  • 54:42 - 54:50
    otherwise I want to run the default
  • 54:45 - 54:51
    function so here's what I've changed
  • 54:50 - 54:53
    with respect to the base commit wherever
  • 54:51 - 54:55
    master is pointing so I've added the dog
  • 54:53 - 54:57
    function and I've changed mean a little
  • 54:55 - 55:00
    bit so a kind of parallel modification
  • 54:57 - 55:03
    to what I did in the cat branch let me
  • 55:00 - 55:05
    go ahead and get add animal Titus add up
  • 55:03 - 55:06
    to the staging area if I do get status
  • 55:05 - 55:08
    I'll see that this change will be
  • 55:06 - 55:12
    committed when I make the next commit
  • 55:08 - 55:16
    and then I do get commit add
  • 55:12 - 55:18
    functionality now when I look at the get
  • 55:16 - 55:20
    graph it actually looks kind of
  • 55:18 - 55:23
    interesting compared to the ones we've
  • 55:20 - 55:24
    looked at before this shows that these
  • 55:23 - 55:26
    three commits
  • 55:24 - 55:27
    are in common with the ones that come
  • 55:26 - 55:29
    after it but then the history is
  • 55:27 - 55:31
    actually forked after this point and I
  • 55:29 - 55:32
    have this one commit that adds cat
  • 55:31 - 55:35
    functionality in one line of development
  • 55:32 - 55:36
    and then I have this other commit that
  • 55:35 - 55:38
    adds dog functionality in this other
  • 55:36 - 55:40
    line of development and then using the
  • 55:38 - 55:43
    git checkout command I can switch back
  • 55:40 - 55:46
    and forth between dog and cat and master
  • 55:43 - 55:48
    so this is great I can do development in
  • 55:46 - 55:49
    parallel on different features but this
  • 55:48 - 55:51
    is only really useful if I can
  • 55:49 - 55:53
    eventually combine those things back
  • 55:51 - 55:55
    into my original line of development to
  • 55:53 - 55:57
    have both features in a single version
  • 55:55 - 56:00
    of my source code so the command that's
  • 55:57 - 56:02
    used to do that is get merge so like get
  • 56:00 - 56:06
    branch and get merge can kind of be
  • 56:02 - 56:10
    thought of as opposites let me check out
  • 56:06 - 56:12
    get check out master let me check out my
  • 56:10 - 56:14
    master branch so now you see head points
  • 56:12 - 56:15
    to master and then I want to merge the
  • 56:14 - 56:17
    cat functionality and the dog
  • 56:15 - 56:19
    functionality into master and to do that
  • 56:17 - 56:21
    I can use the git merge command and get
  • 56:19 - 56:23
    merge is actually pretty fancy and I can
  • 56:21 - 56:25
    actually merge cat and dog at the same
  • 56:23 - 56:26
    time but for this demonstration we're
  • 56:25 - 56:29
    going to only merge one thing at a time
  • 56:26 - 56:32
    so first I'll type git merge cat and
  • 56:29 - 56:34
    gets us some stuff here it says
  • 56:32 - 56:36
    fast-forward so what is going on here
  • 56:34 - 56:38
    well this is one interesting thing that
  • 56:36 - 56:40
    get can do when you're at a particular
  • 56:38 - 56:43
    commit and you merge some other branch
  • 56:40 - 56:46
    in where that other branch has the
  • 56:43 - 56:48
    current commit as a predecessor it's not
  • 56:46 - 56:50
    necessary to create any new snapshots or
  • 56:48 - 56:53
    do any other fancy stuff basically this
  • 56:50 - 56:55
    this master branch here this pointer to
  • 56:53 - 56:57
    this commit can just be moved to point
  • 56:55 - 56:59
    here instead to incorporate that cat
  • 56:57 - 57:02
    functionality and so if we look at the
  • 56:59 - 57:04
    git log again we see that master is
  • 57:02 - 57:07
    basically pointing to the same places
  • 57:04 - 57:08
    wherever cat was pointing all right so
  • 57:07 - 57:10
    now we're on the master branch and it
  • 57:08 - 57:14
    has the cat functionality great we're
  • 57:10 - 57:16
    halfway there if we look at animal dock
  • 57:14 - 57:20
    by it has the cat functionality but it's
  • 57:16 - 57:22
    missing the dog stuff so let's try get
  • 57:20 - 57:24
    merge dog next something a little bit
  • 57:22 - 57:27
    more interesting happens this time so
  • 57:24 - 57:29
    this time the branch can't be fast
  • 57:27 - 57:31
    forwarded like it was before it's not
  • 57:29 - 57:32
    that one thing which is strictly older
  • 57:31 - 57:34
    than the other thing there's been
  • 57:32 - 57:35
    parallel development that may be kind of
  • 57:34 - 57:37
    incompatible with the current set of
  • 57:35 - 57:39
    changes and
  • 57:37 - 57:41
    it does its best job at automatically
  • 57:39 - 57:41
    merging the changes from this other
  • 57:41 - 57:43
    branch
  • 57:41 - 57:46
    so it says Auto merging animal dot pie
  • 57:43 - 57:48
    but in this particular case there's what
  • 57:46 - 57:50
    was what's called a merge conflict so it
  • 57:48 - 57:51
    wasn't able to automatically resolve on
  • 57:50 - 57:53
    the call the conflicts between these two
  • 57:51 - 57:54
    parallel branches of development and
  • 57:53 - 57:56
    this is something you'll see in practice
  • 57:54 - 57:57
    when you're working on real software
  • 57:56 - 58:00
    projects and they're complicated
  • 57:57 - 58:02
    slightly incompatible changes happening
  • 58:00 - 58:04
    in parallel so at this point it's left
  • 58:02 - 58:08
    up to the developer to fix this issue
  • 58:04 - 58:10
    and get offers some functionality in
  • 58:08 - 58:12
    order to help resolve merge conflicts
  • 58:10 - 58:15
    there's a program called git merge tool
  • 58:12 - 58:17
    and in my particular setup this will
  • 58:15 - 58:22
    launch vim diff actually this is not
  • 58:17 - 58:32
    configured them diff I think will start
  • 58:22 - 58:38
    the right program let me set up my get
  • 58:32 - 58:39
    to launch the correct tool actually
  • 58:38 - 58:40
    let's skip that part and let's just
  • 58:39 - 58:42
    manually look at this event if so
  • 58:40 - 58:44
    there's a program called vim diff which
  • 58:42 - 58:46
    can be set up to be launched when you
  • 58:44 - 58:48
    type in get merge tool which is a tool
  • 58:46 - 58:50
    that you use when you try get merged in
  • 58:48 - 58:52
    there merge conflicts but in this
  • 58:50 - 58:52
    particular case we'll just manually
  • 58:52 - 58:56
    resolve them
  • 58:52 - 58:57
    so let me I did get merge - - abort so
  • 58:56 - 58:59
    it put me back in the state I was before
  • 58:57 - 59:00
    I tried that git merge so this is the
  • 58:59 - 59:03
    current state of my repository I'm back
  • 59:00 - 59:05
    to the case where master is at the same
  • 59:03 - 59:08
    place as cat and I'm about to merge in
  • 59:05 - 59:11
    dog so I do get merged dog and it says
  • 59:08 - 59:12
    conflict merge conflict in animal Pi so
  • 59:11 - 59:16
    let's just look at animal dot PI
  • 59:12 - 59:19
    directly so it looks like this top part
  • 59:16 - 59:21
    looks pretty reasonable it has both the
  • 59:19 - 59:23
    cat function and the dog function which
  • 59:21 - 59:24
    is exactly what I want but now I see
  • 59:23 - 59:25
    some weird stuff in main and this is
  • 59:24 - 59:29
    where I add slightly incompatible
  • 59:25 - 59:31
    changes so here it says that in one
  • 59:29 - 59:35
    thing like basically the branch you were
  • 59:31 - 59:36
    on you had this content and then the
  • 59:35 - 59:39
    branch you're trying to merge had this
  • 59:36 - 59:41
    content and then these things here the
  • 59:39 - 59:43
    angle brackets and the equals our
  • 59:41 - 59:44
    conflict markers so this is where you
  • 59:43 - 59:46
    were and this is the thing you're trying
  • 59:44 - 59:48
    to merge in and it's basically saying
  • 59:46 - 59:49
    that it was this on one case this in the
  • 59:48 - 59:50
    other case and it doesn't really know
  • 59:49 - 59:52
    how to resolve
  • 59:50 - 59:54
    these two and it's left up to the
  • 59:52 - 59:56
    programmer to fix this problem so in
  • 59:54 - 59:58
    this particular case we can go ahead and
  • 59:56 - 60:00
    delete the conflict markers and then
  • 59:58 - 60:02
    turns out that we can actually
  • 60:00 - 60:04
    concatenate this code together and does
  • 60:02 - 60:06
    the right thing maybe we want to make a
  • 60:04 - 60:07
    small change like this should be an if
  • 60:06 - 60:10
    this should be an else--if and this
  • 60:07 - 60:13
    should be an else that might make a
  • 60:10 - 60:15
    little bit more sense actually I think
  • 60:13 - 60:17
    it's necessary for correctness here so
  • 60:15 - 60:18
    the programmer needed to modify the code
  • 60:17 - 60:20
    a little bit in order to make it
  • 60:18 - 60:22
    sensible when it's merged together but
  • 60:20 - 60:25
    once the programmer has fixed the merge
  • 60:22 - 60:27
    conflicts fixed the stuff between the
  • 60:25 - 60:30
    conflict markers you can save this file
  • 60:27 - 60:35
    and we can do get merged - - continue to
  • 60:30 - 60:38
    tell git that we fix the issues it's
  • 60:35 - 60:39
    necessary to re add animal PI to tell
  • 60:38 - 60:41
    git that we've actually fixed these
  • 60:39 - 60:43
    issues and then we need to get merged -
  • 60:41 - 60:45
    - continue it pops up an editor and we
  • 60:43 - 60:46
    can give a commit message for this new
  • 60:45 - 60:49
    commit that we're about to create and
  • 60:46 - 60:52
    now if we look at the git history we
  • 60:49 - 60:55
    have the single commit that represents
  • 60:52 - 60:59
    our merge commit that we just made which
  • 60:55 - 61:02
    merges in the dog functionality and here
  • 60:59 - 61:04
    this has as parents both the dog commit
  • 61:02 - 61:06
    and the cat commit
  • 61:04 - 61:07
    so both these branches appear in our
  • 61:06 - 61:09
    history from this point backwards and
  • 61:07 - 61:11
    this current commit that we're on
  • 61:09 - 61:15
    incorporates the functionality from both
  • 61:11 - 61:17
    of these branches so if we run animal
  • 61:15 - 61:18
    duck fight with cat it does the cat
  • 61:17 - 61:20
    thing if we run it with dog it does the
  • 61:18 - 61:22
    dog thing and if we run it with anything
  • 61:20 - 61:24
    else it falls back to the default
  • 61:22 - 61:27
    implementation so this is a
  • 61:24 - 61:29
    demonstration of how you branch and get
  • 61:27 - 61:30
    to do development on different things in
  • 61:29 - 61:33
    parallel and then how you can use the
  • 61:30 - 61:34
    merge command and get to resolve those
  • 61:33 - 61:36
    different branches and combine them
  • 61:34 - 61:38
    together into a single snapshot that
  • 61:36 - 61:41
    includes all the functionality that was
  • 61:38 - 61:43
    developed in parallel with each other
  • 61:41 - 61:45
    and then one thing that can happen when
  • 61:43 - 61:47
    you're doing get branching and merging
  • 61:45 - 61:50
    is you run into merge conflicts and
  • 61:47 - 61:52
    these conflicts show up as conflict
  • 61:50 - 61:54
    markers and text files you can manually
  • 61:52 - 61:55
    resolve them and kit also has some tools
  • 61:54 - 61:57
    that can help with this though these
  • 61:55 - 61:58
    tools are kind of advanced and will only
  • 61:57 - 62:00
    refer to them in the lecture notes and
  • 61:58 - 62:04
    not actually demonstrate them for you
  • 62:00 - 62:09
    so that's get branching and merging
  • 62:04 - 62:12
    any questions no great so moving on to
  • 62:09 - 62:14
    the next topic of this lecture we will
  • 62:12 - 62:16
    talk about git remotes so this is
  • 62:14 - 62:20
    basically how you collaborate with other
  • 62:16 - 62:22
    people using git a git repository the
  • 62:20 - 62:24
    stuff contained in this dot git folder
  • 62:22 - 62:26
    represents kind of an entire copy of the
  • 62:24 - 62:28
    history it has the objects in the
  • 62:26 - 62:31
    references and contains all the previous
  • 62:28 - 62:33
    snapshots and the way you collaborate
  • 62:31 - 62:35
    with other people using git is that
  • 62:33 - 62:38
    other people can also have copies of the
  • 62:35 - 62:42
    entire git repository and then your get
  • 62:38 - 62:44
    copy your local instantiation of the
  • 62:42 - 62:47
    repository can be aware of the existence
  • 62:44 - 62:49
    of other clones of the same repository
  • 62:47 - 62:52
    and this is a concept known as remotes
  • 62:49 - 62:54
    so the git remote command will list all
  • 62:52 - 62:57
    the remotes that git is aware of for the
  • 62:54 - 62:59
    current repository and in our case with
  • 62:57 - 63:01
    this repository right here this command
  • 62:59 - 63:03
    get remote just doesn't print anything
  • 63:01 - 63:06
    because we haven't configured any
  • 63:03 - 63:07
    remotes it is only aware of the single
  • 63:06 - 63:10
    local copy of the repository that we're
  • 63:07 - 63:11
    working with here but in practice if
  • 63:10 - 63:13
    you're collaborating with other people
  • 63:11 - 63:16
    your git might be aware of the copy of
  • 63:13 - 63:17
    the code that is on github and then
  • 63:16 - 63:19
    there's a set of commands to send
  • 63:17 - 63:21
    changes from your local copy of the
  • 63:19 - 63:23
    repository to a remote that your get is
  • 63:21 - 63:25
    aware of so sending stuff from your
  • 63:23 - 63:27
    computer to github for example and
  • 63:25 - 63:29
    there's another set of commands for
  • 63:27 - 63:31
    fetching changes made in a local
  • 63:29 - 63:34
    repository to get changes from github
  • 63:31 - 63:37
    into your own local copy in this
  • 63:34 - 63:39
    demonstration here we actually won't go
  • 63:37 - 63:40
    and configure a github account and log
  • 63:39 - 63:42
    in and create a new repository on there
  • 63:40 - 63:44
    you can find other tutorials for doing
  • 63:42 - 63:47
    that we'll actually just use a separate
  • 63:44 - 63:49
    folder on the same computer and treat it
  • 63:47 - 63:53
    like a git remote so let me I'm in the
  • 63:49 - 63:54
    demo folder here let me go up one
  • 63:53 - 63:56
    directory I have a directory called
  • 63:54 - 64:00
    playground that has this demo folder and
  • 63:56 - 64:04
    I'll go ahead and create a new directory
  • 64:00 - 64:07
    in here and I'll call it remote and then
  • 64:04 - 64:08
    do get in it - - bear in here those are
  • 64:07 - 64:11
    the command that you'll probably never
  • 64:08 - 64:14
    need to use in regular usage but now
  • 64:11 - 64:16
    what I've done is made remote into a
  • 64:14 - 64:17
    folder that's appropriate to use as a
  • 64:16 - 64:19
    git remote
  • 64:17 - 64:22
    so now going back into my demo folder
  • 64:19 - 64:23
    here might mean repository I can do get
  • 64:22 - 64:26
    remote to list the remotes
  • 64:23 - 64:30
    there's nothing yet but I can use the
  • 64:26 - 64:32
    git remote add functionality to make my
  • 64:30 - 64:35
    local repository aware of the existence
  • 64:32 - 64:37
    of a remote so I can do git remote add
  • 64:35 - 64:40
    and then the format for this is that
  • 64:37 - 64:43
    remotes have names and then they have a
  • 64:40 - 64:45
    URL so in this case I'll use the name
  • 64:43 - 64:47
    origin does often use by convention as
  • 64:45 - 64:50
    the name of the remote if you're only
  • 64:47 - 64:51
    using one and then for the URL normally
  • 64:50 - 64:53
    this will be like a github URL or
  • 64:51 - 64:55
    something like that or bitbucket URL or
  • 64:53 - 64:58
    get live URL if you're using an online
  • 64:55 - 65:00
    repository hosting service but in this
  • 64:58 - 65:02
    case it's just a path to a folder on my
  • 65:00 - 65:04
    local machine there's a folder in the
  • 65:02 - 65:06
    parent directory called remote that will
  • 65:04 - 65:09
    act as the git remote for this
  • 65:06 - 65:11
    repository so now once I've done that
  • 65:09 - 65:14
    there's a set of commands for
  • 65:11 - 65:15
    interacting with this remote one command
  • 65:14 - 65:19
    that's useful is the git push command
  • 65:15 - 65:21
    this command can send the changes from
  • 65:19 - 65:23
    your computer to the remote and the
  • 65:21 - 65:25
    format for this command is that git push
  • 65:23 - 65:28
    takes in the name of a remote and then
  • 65:25 - 65:30
    it takes in a local branch name : a
  • 65:28 - 65:31
    remote branch name and what it does is
  • 65:30 - 65:34
    it creates a new branch or updates a
  • 65:31 - 65:37
    branch on the remote with the name
  • 65:34 - 65:40
    specified here and sets it to the
  • 65:37 - 65:42
    contents of the branch specified here so
  • 65:40 - 65:45
    a concrete use of this might look like
  • 65:42 - 65:49
    git push I've only one remote called
  • 65:45 - 65:52
    origin and then what should I push let
  • 65:49 - 65:54
    me look at my history graph I have a
  • 65:52 - 65:57
    bunch of things I could push let me get
  • 65:54 - 65:59
    pushed to origin the master branch from
  • 65:57 - 66:01
    my local machine :
  • 65:59 - 66:04
    master so I want to create a branch on
  • 66:01 - 66:06
    the remote machine with the name master
  • 66:04 - 66:09
    that is going to be the same as the
  • 66:06 - 66:10
    master branch on my local machine so let
  • 66:09 - 66:12
    me go ahead and run that command it
  • 66:10 - 66:14
    prints out some stuff and it says on the
  • 66:12 - 66:16
    remote I created a new branch remote
  • 66:14 - 66:19
    master points to the same branch as
  • 66:16 - 66:23
    master on my local machine and now if I
  • 66:19 - 66:26
    do a git log it shows me so in blue is
  • 66:23 - 66:27
    head where I currently am in green are
  • 66:26 - 66:30
    all the branches in my local git
  • 66:27 - 66:30
    repository and now we see one new color
  • 66:30 - 66:33
    here that we had
  • 66:30 - 66:35
    seen before so in red get shows
  • 66:33 - 66:37
    references that are present on the
  • 66:35 - 66:40
    remotes that my local copy is aware of
  • 66:37 - 66:41
    so on the remote origin there's also a
  • 66:40 - 66:44
    branch that happens to have the name
  • 66:41 - 66:48
    master that points to the same place as
  • 66:44 - 66:50
    my local branch master points and so now
  • 66:48 - 66:53
    if I make updates to my local copies
  • 66:50 - 66:57
    like suppose here I go in and change the
  • 66:53 - 67:00
    capitalization of these things and then
  • 66:57 - 67:01
    get had animal dot hi get commit here's
  • 67:00 - 67:03
    a short form for commit with a message
  • 67:01 - 67:04
    so it doesn't pop up the editor I'll
  • 67:03 - 67:08
    give it a late and commit message and
  • 67:04 - 67:10
    now if I look at the git graph now I see
  • 67:08 - 67:12
    that I've created this new snapshot here
  • 67:10 - 67:16
    that has this lower casing stuff in it
  • 67:12 - 67:18
    but origin master is still back here so
  • 67:16 - 67:20
    if somebody else looks at the remote
  • 67:18 - 67:22
    they will only see the changes up to
  • 67:20 - 67:24
    here and we can actually demonstrate
  • 67:22 - 67:27
    this functionality so let me go ahead
  • 67:24 - 67:30
    and open up a new tab here and go into
  • 67:27 - 67:32
    my playground directory the git clone
  • 67:30 - 67:35
    command is a command that somebody can
  • 67:32 - 67:36
    use to start from some copy of a
  • 67:35 - 67:39
    repository somewhere and make their own
  • 67:36 - 67:40
    local copy so this is often a command to
  • 67:39 - 67:41
    use when starting out with a git repo
  • 67:40 - 67:43
    like there might be something available
  • 67:41 - 67:45
    on github and you want to copy it all in
  • 67:43 - 67:47
    your machine in order to look at it or
  • 67:45 - 67:49
    start doing development and so the
  • 67:47 - 67:51
    format for git clone is that it takes in
  • 67:49 - 67:55
    a URL and then it takes in a name for a
  • 67:51 - 67:58
    folder for where to clone it so in our
  • 67:55 - 68:00
    case here we're just going to clone from
  • 67:58 - 68:01
    this remote directory we're pretending
  • 68:00 - 68:04
    that this remote folder is actually a
  • 68:01 - 68:07
    remote machine and then we're all clone
  • 68:04 - 68:10
    it into the folder called demo two so
  • 68:07 - 68:13
    cloning into demo 2 done and I'm going
  • 68:10 - 68:15
    to CD into that directory and then now
  • 68:13 - 68:20
    here I'm going to rename these tabs at
  • 68:15 - 68:22
    the bottom I will say this one's machine
  • 68:20 - 68:23
    one and this one's machine too so you
  • 68:22 - 68:25
    can think of these as two different
  • 68:23 - 68:28
    people on different machines with their
  • 68:25 - 68:30
    own copy of the repository and they're
  • 68:28 - 68:32
    both interacting with the single remote
  • 68:30 - 68:34
    so if I do my get log command that I've
  • 68:32 - 68:36
    been doing on machine one I see on
  • 68:34 - 68:41
    Machine 2 I see this portion of the
  • 68:36 - 68:43
    history so master on machine 2 is
  • 68:41 - 68:44
    pointing to the same places origin
  • 68:43 - 68:47
    master
  • 68:44 - 68:49
    and it says merge branch dog so if I
  • 68:47 - 68:51
    look at animal dot pie here
  • 68:49 - 68:53
    it doesn't have the changes that I made
  • 68:51 - 68:56
    on machine to even though there are
  • 68:53 - 68:58
    sorry on machine one where I have this
  • 68:56 - 69:00
    new commit that is only present on this
  • 68:58 - 69:03
    machine but not on the remote and not on
  • 69:00 - 69:05
    machine too so if I want to fix that if
  • 69:03 - 69:07
    I want to send these changes up to the
  • 69:05 - 69:09
    remote like think of it as sending it up
  • 69:07 - 69:11
    to github err up to the machine that's
  • 69:09 - 69:14
    holding or maintaining the source code I
  • 69:11 - 69:19
    can use the git push command again git
  • 69:14 - 69:21
    push origin master colon master and this
  • 69:19 - 69:22
    will work but this is kind of annoying
  • 69:21 - 69:24
    to type every time you want to do this
  • 69:22 - 69:26
    like this is a really common operation
  • 69:24 - 69:29
    so git has a way of making this a little
  • 69:26 - 69:32
    bit simpler it has a way of maintaining
  • 69:29 - 69:34
    relationships between branches on your
  • 69:32 - 69:37
    own local machine and branches on remote
  • 69:34 - 69:39
    machines it is a way of knowing what
  • 69:37 - 69:41
    branch on a remote machine a local
  • 69:39 - 69:43
    branch corresponds to so that you can
  • 69:41 - 69:45
    type in a shortened version of git push
  • 69:43 - 69:47
    and it'll know what all the arguments to
  • 69:45 - 69:49
    the expanded form would have been and
  • 69:47 - 69:52
    there a couple different syntaxes for
  • 69:49 - 69:55
    doing this one way is to use the git
  • 69:52 - 69:57
    branch - - set up stream to command and
  • 69:55 - 69:59
    what this does is for the branch that's
  • 69:57 - 70:02
    currently checked out which is master it
  • 69:59 - 70:05
    will set the upstream - and I'll type in
  • 70:02 - 70:07
    origin master and see now it says branch
  • 70:05 - 70:09
    master set up to track remote branch
  • 70:07 - 70:12
    master from origin now if I type in get
  • 70:09 - 70:13
    branch - VV remember this is tell me
  • 70:12 - 70:15
    about all the branches that I know about
  • 70:13 - 70:18
    in a very verbose way that's what the -
  • 70:15 - 70:20
    VV means I have three branches on my
  • 70:18 - 70:23
    local machine on machine one I have cat
  • 70:20 - 70:27
    dog and master and master on my local
  • 70:23 - 70:30
    machine corresponds to origin master so
  • 70:27 - 70:32
    now I can type in just get push without
  • 70:30 - 70:33
    all the extra arguments I could have
  • 70:32 - 70:35
    done this as git push origin master
  • 70:33 - 70:38
    colon master but it wasn't necessary
  • 70:35 - 70:41
    it'll know that I want to push to origin
  • 70:38 - 70:43
    master and it will make that change
  • 70:41 - 70:45
    so now these changes are present on the
  • 70:43 - 70:46
    remote we can go over to machine to
  • 70:45 - 70:49
    pretend we're the other guy interacting
  • 70:46 - 70:51
    with this repository and if I do might
  • 70:49 - 70:53
    get logged command I still don't see the
  • 70:51 - 70:56
    changes so what's going on here
  • 70:53 - 70:57
    well it's necessary in order to run a
  • 70:56 - 70:58
    separate command
  • 70:57 - 71:00
    or it's necessary to run a separate
  • 70:58 - 71:03
    command in order to have these changes
  • 71:00 - 71:05
    present here by default all the get
  • 71:03 - 71:06
    commands don't talk to the internet it
  • 71:05 - 71:09
    all works locally which means it works
  • 71:06 - 71:10
    very fast but then there are special
  • 71:09 - 71:11
    commands for saying that you want to
  • 71:10 - 71:14
    retrieve changes that have made
  • 71:11 - 71:15
    somewhere else and the command that's
  • 71:14 - 71:19
    used for doing that is a command called
  • 71:15 - 71:21
    git fetch get fetch takes thee as an
  • 71:19 - 71:23
    argument the name of the remote but if
  • 71:21 - 71:26
    there's only one it'll just use that so
  • 71:23 - 71:30
    you can type in git fetch and then it's
  • 71:26 - 71:33
    talked to this remote repository and it
  • 71:30 - 71:35
    says that there's some update on the
  • 71:33 - 71:37
    remote and we can visualize it by
  • 71:35 - 71:38
    running git log and now we see here
  • 71:37 - 71:41
    another situation that we hadn't seen
  • 71:38 - 71:43
    before we have master on our local
  • 71:41 - 71:45
    machine the master branch doesn't change
  • 71:43 - 71:47
    the git fetch command doesn't change any
  • 71:45 - 71:49
    of our local history our local
  • 71:47 - 71:52
    references like our branches but now
  • 71:49 - 71:55
    it's aware that origin master has been
  • 71:52 - 71:57
    updated to point to this new commit and
  • 71:55 - 72:01
    there's a separate command we can do get
  • 71:57 - 72:03
    merge in order to move master up to here
  • 72:01 - 72:06
    or there's another command called get
  • 72:03 - 72:09
    pull which is the same as doing git
  • 72:06 - 72:12
    fetch and then get merge so if we just
  • 72:09 - 72:13
    do get pull here for example it will say
  • 72:12 - 72:17
    it's fast forwarding is merging in
  • 72:13 - 72:21
    origin master into our master and now if
  • 72:17 - 72:22
    we look at the git history graph we've
  • 72:21 - 72:24
    currently checked out master master
  • 72:22 - 72:26
    points to the same place as the origin
  • 72:24 - 72:28
    master that we're aware of and all the
  • 72:26 - 72:31
    changes between Machine 2 and Machine 1
  • 72:28 - 72:32
    are in sync so those are the basic
  • 72:31 - 72:33
    commands for interacting with git
  • 72:32 - 72:36
    remotes so there's the git remote
  • 72:33 - 72:37
    command for listing remotes and adding
  • 72:36 - 72:40
    and removing them and things like that
  • 72:37 - 72:42
    and then there's the git push command
  • 72:40 - 72:45
    for sending changes from your local copy
  • 72:42 - 72:47
    of the repository to the remote and then
  • 72:45 - 72:49
    there's the git fetch command which is
  • 72:47 - 72:51
    for retrieving changes to a repository
  • 72:49 - 72:54
    that are present on a remote and getting
  • 72:51 - 72:57
    the changes on your local machine and
  • 72:54 - 72:59
    once you retrieve those changes you can
  • 72:57 - 73:01
    use git merge to update your local
  • 72:59 - 73:03
    branch to point to the same place where
  • 73:01 - 73:05
    the remote branch does or you can use
  • 73:03 - 73:06
    the git pull command which does
  • 73:05 - 73:09
    basically the same thing as get fetch
  • 73:06 - 73:11
    plus git merge and then of course
  • 73:09 - 73:13
    separate from all these commands
  • 73:11 - 73:15
    is the clone command that we talked
  • 73:13 - 73:17
    about a little while ago which is for
  • 73:15 - 73:20
    taking a copy of remote repository and
  • 73:17 - 73:24
    initializing the local repository from
  • 73:20 - 73:26
    that copy so that's a quick overview of
  • 73:24 - 73:28
    the different commands used to interact
  • 73:26 - 73:30
    with git remotes and now these are kind
  • 73:28 - 73:31
    of complicated and it takes a while to
  • 73:30 - 73:33
    master all the different variations of
  • 73:31 - 73:35
    this and understand how they're actually
  • 73:33 - 73:36
    used in practice but hopefully this acts
  • 73:35 - 73:38
    as a quick introduction and you can see
  • 73:36 - 73:41
    how the different commands relate to the
  • 73:38 - 73:43
    underlying data model all these commands
  • 73:41 - 73:44
    all they do is fetch new objects from
  • 73:43 - 73:47
    other places or send objects from the
  • 73:44 - 73:51
    local mission to other places and these
  • 73:47 - 73:54
    commands mutate references so relating
  • 73:51 - 73:56
    these relating the interface of git and
  • 73:54 - 73:58
    some of these kind of badly designed
  • 73:56 - 74:04
    commands to the underlying data model
  • 73:58 - 74:06
    can help it make a lot more sense the
  • 74:04 - 74:09
    final topic we're going to cover today
  • 74:06 - 74:11
    is it's a kind of overview of other
  • 74:09 - 74:13
    things that get can do that we're not
  • 74:11 - 74:15
    going to go into detail in teaching you
  • 74:13 - 74:17
    how to do but we just want to tell you
  • 74:15 - 74:18
    that these functionalities exist in case
  • 74:17 - 74:19
    you need to do these things yourself you
  • 74:18 - 74:22
    can look up the documentation and find
  • 74:19 - 74:25
    out exactly how to do it one thing is
  • 74:22 - 74:27
    the git config command like a lot of
  • 74:25 - 74:28
    tools we've looked at like the shell and
  • 74:27 - 74:30
    T MUX and things like that
  • 74:28 - 74:32
    git is highly configurable and it's
  • 74:30 - 74:34
    configured using a plain text file which
  • 74:32 - 74:36
    can be edited either through the
  • 74:34 - 74:38
    command-line interface so git config can
  • 74:36 - 74:41
    take in flags that will modify this text
  • 74:38 - 74:44
    file or you can edit the dot git config
  • 74:41 - 74:47
    file in the home folder with plain text
  • 74:44 - 74:49
    configuration and so for this lecture
  • 74:47 - 74:53
    I've actually cut out most of them I get
  • 74:49 - 74:55
    config and only left in my username and
  • 74:53 - 74:57
    email for what will go in to get commits
  • 74:55 - 75:00
    but there's a lot of stuff you can put
  • 74:57 - 75:01
    in here which will make it behave nicer
  • 75:00 - 75:03
    it behaved the way you want it to and
  • 75:01 - 75:05
    you can look online for different ways
  • 75:03 - 75:07
    people have configured their get configs
  • 75:05 - 75:07
    oftentimes people have documentation in
  • 75:07 - 75:13
    their kit configs
  • 75:07 - 75:15
    which can be found on github there's a
  • 75:13 - 75:16
    couple other random commands that could
  • 75:15 - 75:19
    be useful one is for when you want to
  • 75:16 - 75:22
    clone a repository with git clone that's
  • 75:19 - 75:25
    really gigantic get cloned by default
  • 75:22 - 75:26
    copies the entire version history for
  • 75:25 - 75:28
    the remote it's downloading the
  • 75:26 - 75:30
    repository from but there's an argument
  • 75:28 - 75:33
    you can pass it which is - - shallow
  • 75:30 - 75:34
    which will avoid doing that so if
  • 75:33 - 75:36
    there's some copy of some code on github
  • 75:34 - 75:37
    say that you want to get a copy copy of
  • 75:36 - 75:39
    on your local machine but that
  • 75:37 - 75:41
    repository is really gigantic and has a
  • 75:39 - 75:43
    billion commits he's get cloned - -
  • 75:41 - 75:44
    shallow this will be much faster but
  • 75:43 - 75:46
    then of course he won't have the version
  • 75:44 - 75:50
    history on your local machine you'll
  • 75:46 - 75:52
    just have the latest snapshot another
  • 75:50 - 75:53
    command that we find really useful when
  • 75:52 - 75:56
    doing development on real software
  • 75:53 - 75:58
    projects is an interactive version of
  • 75:56 - 75:59
    the git add command so to demonstrate
  • 75:58 - 76:02
    this I'm going to go ahead and make a
  • 75:59 - 76:05
    couple different changes to my animal PI
  • 76:02 - 76:08
    one change I'll make here I'll change
  • 76:05 - 76:10
    some text here and then I'll put a new
  • 76:08 - 76:12
    print statement here so let's pretend
  • 76:10 - 76:13
    that this first change was some real
  • 76:12 - 76:16
    change I wanted to make say it's a bug
  • 76:13 - 76:18
    fix and this other change here was a
  • 76:16 - 76:19
    printf that I added for debugging but I
  • 76:18 - 76:22
    don't actually want to commit in the
  • 76:19 - 76:23
    next snapshot if I do a get diff it'll
  • 76:22 - 76:26
    show me that yes I've made these two
  • 76:23 - 76:29
    changes and if I do get add animal dot
  • 76:26 - 76:31
    pi it will stage both of those changes
  • 76:29 - 76:33
    for a commit and that's not what I want
  • 76:31 - 76:35
    I could go manually remove this debug
  • 76:33 - 76:37
    print and then do this get animal dog
  • 76:35 - 76:38
    get add animal dot PI but there's an
  • 76:37 - 76:40
    easier way to do it
  • 76:38 - 76:43
    there's this get add - pika man which
  • 76:40 - 76:45
    lets me interactively stage pieces of
  • 76:43 - 76:47
    files for it commit and so there's some
  • 76:45 - 76:48
    interface for working with this so here
  • 76:47 - 76:49
    it's saying do I want to stage both of
  • 76:48 - 76:51
    these changes and no I don't but I'm
  • 76:49 - 76:53
    going to split it into two smaller
  • 76:51 - 76:55
    changes this one I do want to keep so I
  • 76:53 - 76:58
    say Y for yes and this one I don't want
  • 76:55 - 77:02
    to keep so I say n for no and then if I
  • 76:58 - 77:04
    do get diff - - cached this will show me
  • 77:02 - 77:06
    what changes are staged for commit so
  • 77:04 - 77:08
    now it shows only the actual change I
  • 77:06 - 77:10
    wanted to keep if I do get diff it'll
  • 77:08 - 77:13
    still show me the other change that is
  • 77:10 - 77:14
    not going to be part of the next the
  • 77:13 - 77:16
    next commit which is the change I didn't
  • 77:14 - 77:19
    want to keep and then with this I can do
  • 77:16 - 77:21
    get commit specify some commit message
  • 77:19 - 77:23
    now I only have this change left and
  • 77:21 - 77:26
    then I can do get check out animal to
  • 77:23 - 77:28
    apply to throw away this change so get
  • 77:26 - 77:32
    add - P for interactive staging is a
  • 77:28 - 77:34
    useful thing a couple other commands
  • 77:32 - 77:37
    that you can look up on your own are the
  • 77:34 - 77:39
    get blame command so this commands kind
  • 77:37 - 77:41
    of ominous but it can be used to figure
  • 77:39 - 77:42
    who edited what line of a file and you
  • 77:41 - 77:44
    can also find the corresponding commit
  • 77:42 - 77:46
    that was responsible for modifying that
  • 77:44 - 77:47
    particular line of that file and then
  • 77:46 - 77:49
    you can look up commit messages
  • 77:47 - 77:50
    associated with that and whatnot so this
  • 77:49 - 77:52
    is not that interesting to do in our
  • 77:50 - 77:54
    current toy repository but I'll go over
  • 77:52 - 77:57
    to the repository for the class website
  • 77:54 - 77:59
    and we can look at some particular file
  • 77:57 - 78:01
    here and let me go to some particular
  • 77:59 - 78:03
    line here and I can be looking at this
  • 78:01 - 78:05
    me like oh why was this particular line
  • 78:03 - 78:08
    added what does it mean and I can look
  • 78:05 - 78:12
    at the git blame for this so if I do get
  • 78:08 - 78:13
    blame config dot yml it'll print out all
  • 78:12 - 78:15
    the lines kind of in the right column
  • 78:13 - 78:17
    and then in the left side it'll show me
  • 78:15 - 78:20
    what commits that change was made in and
  • 78:17 - 78:25
    by whom and then looking at this like I
  • 78:20 - 78:28
    can go down to this collections line it
  • 78:25 - 78:30
    was made in this commit that's the last
  • 78:28 - 78:32
    commit that modified that line and now I
  • 78:30 - 78:34
    can use the git show command to get
  • 78:32 - 78:36
    information for that particular commit
  • 78:34 - 78:38
    oh and this is kind of useful redo
  • 78:36 - 78:40
    lectures is a collection that's probably
  • 78:38 - 78:43
    what was related to that collections
  • 78:40 - 78:45
    line and then beyond just showing the
  • 78:43 - 78:48
    commit and the commit message it also
  • 78:45 - 78:49
    shows me the actual changes introduced
  • 78:48 - 78:50
    in that particular commit and they can
  • 78:49 - 78:53
    go look through them and understand
  • 78:50 - 78:55
    what's going on another kind of cool
  • 78:53 - 78:57
    command is a command called git stash so
  • 78:55 - 78:59
    let's go back to our demo repository and
  • 78:57 - 79:05
    demonstrate that here so say if some
  • 78:59 - 79:08
    changes here and I temporarily want to
  • 79:05 - 79:10
    put them away if I do get stash it will
  • 79:08 - 79:12
    revert my working directory to the state
  • 79:10 - 79:16
    it was in at the last commit so if I do
  • 79:12 - 79:17
    cat hollow text that change is gone but
  • 79:16 - 79:20
    it's not just deleted its saved
  • 79:17 - 79:22
    somewhere and if I do get stash pop it
  • 79:20 - 79:26
    will undo the stash so now if I look at
  • 79:22 - 79:29
    hello text it has the changes I made so
  • 79:26 - 79:30
    yet another useful command another
  • 79:29 - 79:33
    really neat command is something called
  • 79:30 - 79:33
    git bisect and this has a complicated
  • 79:33 - 79:36
    interface that we're not going to
  • 79:33 - 79:37
    demonstrate in detail but basically this
  • 79:36 - 79:38
    is a tool that can be used to solve a
  • 79:37 - 79:40
    bunch of problems where you need to
  • 79:38 - 79:43
    manually search history for something
  • 79:40 - 79:44
    suppose you're in a scenario where
  • 79:43 - 79:45
    you've been working on a project for a
  • 79:44 - 79:47
    long time you have lots and lots of
  • 79:45 - 79:49
    snapshots you're a thousand commits in
  • 79:47 - 79:51
    and then you notice that some unit test
  • 79:49 - 79:52
    doesn't pass anymore but you know that
  • 79:51 - 79:54
    this was passing like
  • 79:52 - 79:56
    year ago and you're trying to figure out
  • 79:54 - 79:58
    at what point did it break like at what
  • 79:56 - 80:00
    point was this regression in your code
  • 79:58 - 80:02
    introduced so one thing you could do is
  • 80:00 - 80:03
    manually check out like go back one
  • 80:02 - 80:04
    commit and see if the unit test is still
  • 80:03 - 80:06
    failing go back one commit see if it's
  • 80:04 - 80:08
    still failing and eventually you'll find
  • 80:06 - 80:10
    the first commit where the test stopped
  • 80:08 - 80:13
    working and it'll probably tell you like
  • 80:10 - 80:15
    what broke but that's kind of annoying
  • 80:13 - 80:18
    to do manually get by sight automates
  • 80:15 - 80:19
    that process and it actually binary
  • 80:18 - 80:22
    searches your history so it does this in
  • 80:19 - 80:24
    the most efficient way possible and not
  • 80:22 - 80:25
    only that get bisect can take in a
  • 80:24 - 80:27
    scripts that it uses to try to figure
  • 80:25 - 80:29
    out whether a committed looking at is
  • 80:27 - 80:31
    good or bad so it can be a fully
  • 80:29 - 80:33
    automated process like you can give git
  • 80:31 - 80:35
    bisect a unit test and say find the
  • 80:33 - 80:37
    first commit where this unit test
  • 80:35 - 80:42
    stopped passing it's a really powerful
  • 80:37 - 80:44
    tool another random thing that's kind of
  • 80:42 - 80:48
    useful is something called a git ignore
  • 80:44 - 80:50
    file so by default if you have random
  • 80:48 - 80:56
    files in a directory like let me create
  • 80:50 - 80:58
    the dot d s underscore store file whoops
  • 80:56 - 81:02
    create the dot d s underscore store file
  • 80:58 - 81:04
    and then do git status so D s stores
  • 81:02 - 81:05
    like some nuisance file that Mac OS
  • 81:04 - 81:07
    creates I don't know exactly what goes
  • 81:05 - 81:09
    in here but basically once this file is
  • 81:07 - 81:11
    in this directory now whenever I do get
  • 81:09 - 81:13
    status it says oh there's this new file
  • 81:11 - 81:14
    that I've never heard of it before but
  • 81:13 - 81:17
    it apparently here like do you want to
  • 81:14 - 81:18
    add it and this sort of tough stuff gets
  • 81:17 - 81:21
    annoying and there's a lot of other
  • 81:18 - 81:22
    stuff beyond OS specific garbage that
  • 81:21 - 81:24
    might be in a directory like for example
  • 81:22 - 81:26
    if you're working with C code you might
  • 81:24 - 81:28
    compile it and produce dot o files or
  • 81:26 - 81:30
    executable files or things like that and
  • 81:28 - 81:31
    you probably don't want binaries to be
  • 81:30 - 81:34
    part of your commit history you only
  • 81:31 - 81:37
    want the source code and so git has a
  • 81:34 - 81:39
    way of you being able to tell the tool
  • 81:37 - 81:40
    that you don't care about a particular
  • 81:39 - 81:42
    set of files and to ignore them and
  • 81:40 - 81:45
    that's something called a git ignore
  • 81:42 - 81:47
    file so if I go and modify the file
  • 81:45 - 81:49
    called git ignore in the current
  • 81:47 - 81:52
    directory I can specify particular file
  • 81:49 - 81:54
    names or patterns of file names like say
  • 81:52 - 81:57
    I can specify star dot o so any file
  • 81:54 - 82:00
    ending in dot o along with da store and
  • 81:57 - 82:01
    now if I touch food oh and now do a get
  • 82:00 - 82:03
    status
  • 82:01 - 82:05
    I'll see that git says okay I've
  • 82:03 - 82:06
    hollowed out tax which I've modified
  • 82:05 - 82:07
    sure and
  • 82:06 - 82:10
    and I have get ignore so you should
  • 82:07 - 82:13
    track your get ignore file using it but
  • 82:10 - 82:16
    notice that it doesn't mention my dot d
  • 82:13 - 82:17
    s store file or my food out o file
  • 82:16 - 82:21
    that's present in the current directory
  • 82:17 - 82:23
    because that has been get ignored so
  • 82:21 - 82:24
    that's a quick overview of a little bit
  • 82:23 - 82:26
    of advanced get functionality just to
  • 82:24 - 82:30
    give you a flavor of what sorts of cool
  • 82:26 - 82:33
    things this tool can do and then finally
  • 82:30 - 82:34
    we have a couple other topics that are
  • 82:33 - 82:37
    covered in the lecture notes in more
  • 82:34 - 82:39
    detail I'll just quickly list them here
  • 82:37 - 82:41
    so you know what to look for one is that
  • 82:39 - 82:44
    there are many graphical clients forget
  • 82:41 - 82:46
    we don't personally use them we like the
  • 82:44 - 82:47
    git command line tool but some of them
  • 82:46 - 82:49
    are kind of ok and you might want to
  • 82:47 - 82:53
    check them out just to see if you prefer
  • 82:49 - 82:55
    using those another thing is shell
  • 82:53 - 82:57
    integration so you've noticed that in
  • 82:55 - 82:58
    this tutorial I've done get status a
  • 82:57 - 83:01
    whole bunch to see kind of what's going
  • 82:58 - 83:02
    on with my repository well that's kind
  • 83:01 - 83:04
    of annoying to do and a lot of people
  • 83:02 - 83:06
    have their shell prompts set up so that
  • 83:04 - 83:08
    just within this shell prompt itself
  • 83:06 - 83:10
    like on every line it will show me a
  • 83:08 - 83:12
    very succinct summary of what's going on
  • 83:10 - 83:14
    with my repository so it might show me a
  • 83:12 - 83:16
    summary of what branch I have currently
  • 83:14 - 83:18
    checked out along with maybe if I've
  • 83:16 - 83:19
    modified files or untracked files and so
  • 83:18 - 83:21
    we have a link in the lecture notes on
  • 83:19 - 83:25
    how to get some nice shell integration
  • 83:21 - 83:28
    for displaying kind of get related
  • 83:25 - 83:29
    information in your shell prompt similar
  • 83:28 - 83:31
    to that you can get integrations with
  • 83:29 - 83:35
    your text editor so for example I use
  • 83:31 - 83:37
    vim and I have a plug-in for vim that
  • 83:35 - 83:38
    does all sorts of interesting get
  • 83:37 - 83:40
    related stuff one thing I can do with
  • 83:38 - 83:42
    this plug-in is look at get blame
  • 83:40 - 83:43
    information remember we just looked at
  • 83:42 - 83:45
    this through the command line instead I
  • 83:43 - 83:47
    can look at it with this plug-in and it
  • 83:45 - 83:49
    lets me work with it a lot faster I can
  • 83:47 - 83:50
    look at get blame press enter when
  • 83:49 - 83:53
    hovering over a specific commit and it
  • 83:50 - 83:55
    shows me that particular commit in my
  • 83:53 - 83:57
    text editor it even hides all the other
  • 83:55 - 83:58
    files and shows me just the one file I
  • 83:57 - 84:00
    was looking at which is presumably what
  • 83:58 - 84:05
    I care about so we have links to that in
  • 84:00 - 84:06
    the lecture notes as well and there are
  • 84:05 - 84:08
    a couple of there interesting things you
  • 84:06 - 84:11
    could look at there if you're interested
  • 84:08 - 84:12
    finally this lecture by itself is
  • 84:11 - 84:14
    probably not enough to teach you
  • 84:12 - 84:16
    everything you need to know about git
  • 84:14 - 84:18
    it's a good start we think that the
  • 84:16 - 84:18
    right way of learning get was to learn
  • 84:18 - 84:20
    about
  • 84:18 - 84:21
    the underlying data model the whole
  • 84:20 - 84:23
    objects and references and how get
  • 84:21 - 84:25
    models history and then we gave you an
  • 84:23 - 84:27
    introduction to using the git commands
  • 84:25 - 84:29
    and if you want to become really
  • 84:27 - 84:31
    proficient at this tool in the resources
  • 84:29 - 84:34
    section in the lecture notes for today
  • 84:31 - 84:36
    we have a link to a book called pro git
  • 84:34 - 84:38
    so this is a free book it's nicely
  • 84:36 - 84:39
    written it's pretty short and I think
  • 84:38 - 84:41
    going through the first couple chapters
  • 84:39 - 84:42
    of that book should teach you basically
  • 84:41 - 84:44
    everything you need to know in order to
  • 84:42 - 84:46
    use get proficiently for real software
  • 84:44 - 84:48
    projects and for contributing
  • 84:46 - 84:51
    it's a project on github and things like
  • 84:48 - 84:52
    that and then finally just like all the
  • 84:51 - 84:54
    other lectures we have a number of
  • 84:52 - 84:56
    exercises you can go to go through if
  • 84:54 - 84:58
    you want some interesting and
  • 84:56 - 85:00
    challenging problems that you can figure
  • 84:58 - 85:00
    out how to do
Title:
Lecture 6: Version Control (git) (2020)
Description:

more » « less
Video Language:
English
Duration:
01:25:00

English subtitles

Revisions