How to add and commit files in one command?

git commit -a

To add changes to the staging area and commit them in one command use git commit -a.

It will stage modified and deleted files, but new files won't be affected.

You can also add an optional parameter -m 'msg' to add the commit message in the same command.

Layer 1
Terminal Example
git status
On branch main
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git restore ..." to discard changes in working directory)
    modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
git commit -a -m 'Updated README'
[main 1336ca2] Updated README
 1 file changed, 1 insertion(+)
git status
On branch main
nothing to commit, working tree clean

See git commit to learn more about it.

Last modified on November 30, 2021.

You might also like