1. Home
  2. Git
  3. Git Tutorial
  4. Git – Commit Files

Git – Commit Files

Git Commit Files

Use git commit command to commit changes to local git repository. The changes can be any new files added or any existing files content updated etc.


git commit [-a] [-m "Commit Message"]

Git Commit Examples

  • You have a working project on your system and added few new files and modified some existing file.
  • Now you can use git add command to temporarily store the modified files to the staging area called the “index”.
  • Now use below command to commit all files from the staging area to working tree.
git commit -m "Updated Documents"

 3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 Documents/1.pdf
 create mode 100644 Documents/2.pdf
 create mode 100644 README.md

Some users don’t add changes to the staging area and tried to commit files with above command and failed. It means your modified files are not staged.

You can use -a option to commit all modified or deleted files even they are not staged. The -a do corresponding git add and git rm for you.

git commit -a -m "Updated Documents"

 3 files changed, 3 insertions(+), 1 deletion(-)
 create mode 100644 Documents/file1.pdf
 create mode 100644 index.html

Your files have been successfully committed to the current working directory. You can view the commit logs before pushing them to the remote repository.

git log

commit 86da8f0be29dd6d1f9ce3913be4f353fc4ecb9fb
Author: Rahul Kumar 
Date:   Wed Mar 14 10:09:24 2018 +0000

    Updated Documents

commit 7b480fe93bd9ed5deb9da2da3d709e8370056a7f
Author: Rahul 
Date:   Wed Mar 14 10:01:24 2018 +0000

    Updated Documents
Tags , , ,