Creating a Git Commit

The git-commit com­mand takes accepts mes­sage (using the -m switch) where you describe what the changes are con­tained in the commit.

$ git commit -m "adding new file"
  [master (root-commit) 0542a0f] adding first file
	1 file changed, 133 insertions(+)
	create mode 100755 1-basics.rb

The out­put showed that there was 1 file change and 133 inser­tion (addi­tions to the file).

Now if we check the sta­tus again, we’ll see this:

$ git status
  On branch master
  Untracked files:
  (use "git add <file>..." to include in what will be committed)
  nothing added to commit but untracked files present (use "git add" to track)

Let’s add the remain­ing files but this time in bulk using git-add and the dot syn­tax to include every­thing in the cur­rent work­ing directory.

$ git add .

Check­ing the sta­tus again will show all of the pre­vi­ous­ly untracked files ready for a commit:

$ git status
  On branch master
	Changes to be committed:
	  (use "git reset HEAD <file>..." to unstage)
  new file:   .gitignore
  new file:   2-expressions_and_operators.rb
  new file:   3-objects_and_classes.rb
  new file:   4-inheritance.rb
  new file:   5-modules_and_mixins.rb
  new file:

And now we can com­mit those staged files.

$ git commit -m "adding remaining files to repository."
  [master 10183ab] adding remaining files to repository
  6 files changed, 251 insertions(+)
  create mode 100755 .gitignore
  create mode 100755 2-expressions_and_operators.rb
  create mode 100755 3-objects_and_classes.rb
  create mode 100755 4-inheritance.rb
  create mode 100755 5-modules_and_mixins.rb
  create mode 100755

And run­ning git-status again shows that there are no more untracked files and our work­ing direc­to­ry is clean.

  $ git status
  On branch master
  nothing to commit, working directory clean

That’s the basics of work­ing with files in Git. If we didn’t have a set of files already, we could have also ini­tial­ized an emp­ty repos­i­to­ry (also using git-init) and then added files in as we cre­at­ed them.