The git add command adds a change in your working code to the staging area. It does not change the repository, it just marks this change as one to be included with the next commit:
$ vim SomeFile.sh
$ git add SomeFile.sh
Doing a git add after every edit session is a good policy if you want to be certain you don't accidently leave out a change when you commit your changes.
You can also add new files to your repository with the git add command:
$ echo "my test file" >testfile.txt
$ git add testfile.txt
Alternatively, you can add multiple files:
$ git add *.c
The git commit command commits the changes to the repository:
$ vim OtherFile.sh
$ git add OtherFile.sh
$ git commit
The git commit command will open the editor defined in your EDITOR shell variable and pre-populate like this:
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Committer: Clif Flynt <clif@cflynt.com>
#
# On branch branch1
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: SomeFile.sh
# modified: OtherFile.sh
After you enter a comment your changes will be saved in your local copy of the repository.
This does not push your changes to the main repository (perhaps github), but other developers can pull the new code from your repository if they have an account on your system.
You can shorten the add/commit events with the -a and -m arguments to commit:
- -a: This adds the new code before committing
- -m: This defines a message without going into the editor
git commit -am "Add and Commit all modified files."