This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.

add


Adding files to a local repository.

Now that we have initialized an empty repository, lets add a couple of files and use Git to index them. For this excercise, we will add a README and LICENSE file to our empty directory. Don't worry about the file contents for now, empty files will do.

cd /home/username/project
touch README
touch LICENSE

Next, lets ask Git what it thinks of the status of our directory:

git status -s
?? LICENSE
?? README

It looks like Git is unsure about the newly discovered files. We can tell Git to index our files by adding them to the local index:

git add README LICENSE 

And now we can see what Git thinks about the directory contents:

git status -s
A  README
A  LICENSE

Alternatively, we can use the following commands to add all files in a directory or all files in a directory tree recursively:

git add .

git add ..

The only difference is the number of dots. One dot for the current working directory and two dots for the current working directory and all sub-directories.

Further Reading

Git Manual: add

Git Reference: Basic
 

Task Discussion


  • holdenweb   Oct. 13, 2011, 3:12 a.m.

    Couldn't there be a "next task" link on these pages? It's somewhat invonvenient when trying to get up to speed to have to go back to the tasks list simply to select the next link on the list. I have (now, just) noticed the links at the left, but since they appear below the level of the content they are not obvious to an inexperienced user, who might anyway prefer to simply go through the lessons/tasks in sequence.

    And, by the way, I am still exceedingly puzzled as to why you had me sign up for bettercodes, given that everything so far appears to be working with a local repository. So it mght be better to flag that this isn't needed until later. Or, better still, not to specify that task so early.

  • Matija Šuklje   Oct. 31, 2012, 4:34 a.m.
    In Reply To:   holdenweb   Oct. 13, 2011, 3:12 a.m.

    I moved that task to the end of the “course” for now.