We have created Git repository and we made some change to files, then we need to do the following steps, in order:

  1. Add the file to staging area.
  2. Commit staging area (files) into (local) repository.

Then, optionally, you can git push to a remote repository. [see Git: Push to Server]

When using git, you should always cd to your project dir first.

How to commit a change?

After you made changes to the file, then you can commit your changes to local repository. To commit, cd to the working dir, then do:

# commit one file

git add myFile.htm

git commit myFile.htm -m "Message about your Chnages"

Any file you want to commit, you must first git add, even if the file already exists in the repository.

The git add command basically means add it to the “index” file. The purpose of “index” is for next commit. This “index” file is also called “staging area”.


# commit several files
git add file1 file2
git commit -m "new changes."
# commit all files in current dir (not including newly created files)
git add .
git commit -m "new changes"
# commiting all files in current dir, including new or deleted file/dir
git add -A .
git commit -m "new Changes"

The -A option will include any new files in your dir, or files you deleted. Basically, it'll commit your working dir to the local repository.

How to add a new file or dir?

Use the command git add, then git commit.

git add myFile.htm # add a new file

git commit myFile.htm -m "Message about your changes"

How to unadd a file?

If you added a file by mistake, you can unadd.

# unadd a file
git reset myFileName
# unadd all added files in current dir
git reset .

How to delete a file or dir?

Use the git rm command, then commit. The git rm command is similar to git add, in the sense that both changes the staging area.

git rm file_name
git commit file_name -m "Message about your changes"
git rm -r dir_name
git commit dir_name -m "Message about your changes"

git will delete the files/dir for you.

If you already deleted the files, you can still call git rm to update the staging area, then do a commit.

With git, you normally never use git rm command. You simply {delete, add, change} files on your working tree in your normal work flow. When all's good, simply git add -A . then git commit . -m "msg". Git will automatically take care of removed files, or files that changed name.

# commiting all files in current dir, including new or deleted file/dir

git add -A .

git commit -m "Message about your changes"