Initializing a Git Repository
The first step in using Git with a new repository is to initialize the repository.
I have a directory — called learn-ruby
—of existing files that I want to use as a starting point for my new project. In this case the files are just a collection 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 initialize the learn-ruby
directory as a Git repository. To do that, I use the git-init
command inside the directory:
git init .
And you should get something like this:
Initialized empty Git repository in /Users/ryan/projects/
git-classroom-training/learn-ruby/.git/
Notice the .git
directory. That was created by git-init
and it’s the heart of the repository. We’ll get into the specifics of the .git
directory later on, so let’s continue on with our repository.
Next, let’s check the status of the repository 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 directory, however 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 exported from: https://github.com/sintaxi/learn-ruby)