Initializing a Git Repository

The first step in using Git with a new repos­i­to­ry is to ini­tial­ize the repository.

I have a direc­to­ry — called learn-ruby—of exist­ing files that I want to use as a start­ing point for my new project. In this case the files are just a col­lec­tion of Ruby files.

$ ls -al
1-basics.rb                    3-objects_and_classes.rb       5-modules_and_mixins.rb
2-expressions_and_operators.rb 4-inheritance.rb               README.md

I want to ini­tial­ize the learn-ruby direc­to­ry as a Git repos­i­to­ry. To do that, I use the git-init com­mand inside the directory:

git init .

And you should get some­thing like this:

Initialized empty Git repository in /Users/ryan/projects/
git-classroom-training/learn-ruby/.git/

Notice the .git direc­to­ry. That was cre­at­ed by git-init and it’s the heart of the repos­i­to­ry. We’ll get into the specifics of the .git direc­to­ry lat­er on, so let’s con­tin­ue on with our repository.

Next, let’s check the sta­tus of the repos­i­to­ry using git-status.

$ git status
On branch master
	
Initial commit
	
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	
  .gitignore
  1-basics.rb
  2-expressions_and_operators.rb
  3-objects_and_classes.rb
  4-inheritance.rb
  5-modules_and_mixins.rb
  README.md

Git sees the files we have in the direc­to­ry, how­ev­er it marks them all as untracked. But Git gives us a hint as to our next step: add the files using git-add.

(This set of files export­ed from: https://​github​.com/​s​i​n​t​a​x​i​/​l​e​a​r​n​-ruby)