Return to Video

Staging Area - How to Use Git and GitHub

  • 0:00 - 0:03
    Now that you've learned how to initialize an empty Git repository,
  • 0:03 - 0:06
    let's talk about how to add changes to a repository.
  • 0:06 - 0:09
    In my recipes directory, I have the three files,
  • 0:09 - 0:12
    cakerecipe.txt, frostingrecipe.txt and
  • 0:12 - 0:17
    chilirecipe.txt, on my hard drive, which is called my working directory.
  • 0:17 - 0:21
    I also have an empty Git repository that I just created.
  • 0:21 - 0:23
    Now I'd like to add a commit to this repository.
  • 0:23 - 0:26
    Now, you might think I could just run git commit to create a snapshot of
  • 0:26 - 0:28
    the current state of my files.
  • 0:28 - 0:31
    However, Git allows you a bit more control than this.
  • 0:31 - 0:35
    Recall that it's a good idea to keep commits small with one commit per
  • 0:35 - 0:36
    logical change.
  • 0:36 - 0:40
    Git makes it easier for you to do this by allowing you to specify exactly what
  • 0:40 - 0:41
    changes should be committed.
  • 0:41 - 0:46
    To accomplish this, Git uses an intermediate area called the staging area.
  • 0:46 - 0:49
    You can add files one at a time to the staging area.
  • 0:49 - 0:53
    For example, first time I add the cake recipe and then the frosting recipe.
  • 0:53 - 0:56
    Then, when I'm ready to commit, Git bundles the entire contents of
  • 0:56 - 1:01
    the staging area into a single commit and adds that to the repository.
  • 1:01 - 1:03
    Let's see how this works on the command line.
  • 1:03 - 1:07
    To remember what I've added so far, I'll use git status.
  • 1:07 - 1:10
    And I see that I still need to make my initial commit and
  • 1:10 - 1:12
    my three files are still untracked.
  • 1:12 - 1:16
    Now, the command to add files to the staging area is called git add.
  • 1:16 - 1:20
    First, I'll add the file cake-recipe.txt and then I'll add the file
  • 1:20 - 1:23
    frosting-recipe.txt since I think it makes sense to put the cake and
  • 1:23 - 1:25
    the frosting recipes in the same commit.
  • 1:25 - 1:27
    Now I'll run git status again and
  • 1:27 - 1:33
    I can see that these files show up as new files under changes to be committed.
  • 1:33 - 1:36
    This is Git's way of saying that they have been added to the staging area
  • 1:36 - 1:39
    since if I created a commit now, these files would be included.
  • 1:39 - 1:42
    Now go ahead and use git add to add whatever files from your reflections
  • 1:42 - 1:45
    repository you would like to put in your first commit.
  • 1:45 - 1:48
    Which file or files will you add?
  • 1:48 - 1:51
    Will you add both files in one commit or will you use separate commits for
  • 1:51 - 1:52
    each file, and why?
  • 1:52 - 1:53
    Write your answer in this box.
  • 1:54 - 1:58
    After your staging area contains the changes you want in your fist commit,
  • 1:58 - 2:00
    run git status and paste the output in this box.
Title:
Staging Area - How to Use Git and GitHub
Description:

more » « less
Video Language:
English
Team:
Udacity
Project:
UD775 - How to Use Git and GitHub
Duration:
02:02
Udacity Robot edited English subtitles for 03-07 Staging Area
Udacity Robot edited English subtitles for 03-07 Staging Area
Cogi-Admin edited English subtitles for 03-07 Staging Area

English subtitles

Revisions Compare revisions