Git stage and commit with one command

Solution 1:

What you want to do is:

git commit -am "Message for my commit"

This will automatically add all tracked files and you can type your message in one command.

-a --all
Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.

-m <msg> --message=<msg>
Use the given as the commit message. If multiple -m options are given, their values are concatenated as separate paragraphs.

https://git-scm.com/docs/git-commit

If you want to stage and commit untracked files, you can:

git add -A && git commit -am 'message'

Solution 2:

git commit -a ... will automatically add and commit files that have already been commited previously and are modified or deleted now. As you found out it does not affect new files.

You could use an alias to combine the git add ... and git commit ... into one command line. But if you do, take the time to script it to not need to use git add . or git add -A as that will inevitably lead to commiting files you really don't want to.

Solution 3:

You can do this by using an alias.

Define an alias like this:

git config --global alias.your-alias '!git add -A && git commit'

Then you can use it like a normal git command: git your-alias -m 'commit message'