How can you commit a file in Git?

First stage the file with git add, and then commit it with a message.

Terminal output

$ git add hello.txt
$ git commit -m "Add hello.txt"
[main (root-commit) 7757fcb] Add hello.txt
1 file changed, 1 insertion(+)
create mode 100644 hello.txt

To commit tracked files without a separate add, use git commit -a -m "message". To commit only one specific file, you can write its name: git commit hello.txt -m "message". A commit stays on your computer until you push it. See Git Commit.


Learn more about the similar topics:
Tutorials
Git Init
Git Status
Git Add
Git Commit
Git Log
Git Diff
Git Ignore (.gitignore)
Exercises & Assignments
Check the status of files in a Git repository
Stage only selected files and commit them separately
Show the commit history in one line per commit
See the changes of a file before staging and before commit
Ignore all .log files with .gitignore
Unstage a file
Delete a file with git rm
Interview Questions & Answers
How can you add files to Git?
How can you commit a file in Git?
What are the common files to ignore in Git?
How to remove untracked files in Git?
What is the staging area in Git?
What is the difference between git add and git commit?
What is HEAD in Git?