How can I stage and commit all files, including newly added files, using a single command?
-
2There's a duplicate of this at [git add -A, git commit in one command?](http://stackoverflow.com/questions/4298960/git-add-a-git-commit-in-one-command). The accepted answer there is similar to the accepted answer here but suggests creating a git alias to shorten the typing involved (and shows how to do so). – Mark Amery Aug 25 '15 at 23:18
-
5The frustrating thing is that this used to be possible and was standard syntax to commit and add any new files: git commit -a But true to form, the git syntax changed. It confused existing users (and broke their scripts), eliminated useful functionality, and substituted an unnecessary flag. – fijiaaron Feb 07 '15 at 16:41
-
Possible duplicate of [Git add and commit in one command](https://stackoverflow.com/questions/4298960/git-add-and-commit-in-one-command) – Luciano Aug 15 '19 at 09:38
15 Answers
Does
git add -A && git commit -m "Your Message"
count as a "single command"?
Edit based on @thefinnomenon's answer below
To have it as a git alias
, use:
git config --global alias.coa "!git add -A && git commit -m"
and commit all files, including new files, with a message with:
git coa "A bunch of horrible changes"
Explanation
From git add
documentation:
-A, --all, --no-ignore-removal
Update the index not only where the working tree has a file matching but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree.
If no
<pathspec>
is given when -A option is used, all files in the entire working tree are updated (old versions of Git used to limit the update to the current directory and its subdirectories).

- 6,148
- 6
- 38
- 76

- 43,011
- 8
- 86
- 87
-
4
-
11
-
1one could put that in it's own .sh or .bat file and just use it as one command. The message might be param1 – BlueWizard Sep 29 '16 at 06:06
-
And also you can add shortcuts for basic git commands in your .bashrc: alias gpl='git pull' alias gps='git push' alias gc='git commit' alias gs='git status' alias gd='git diff' alias ga='git add' alias gck='git checkout' alias gb='git branch' alias gl='git log' alias lcp='git format-patch -1 HEAD' alias resetToMaster='git reset --hard origin/master' – ni3 Apr 03 '17 at 08:09
-
4In powershell replace "&&" for ";" to run both commands, like this: `git add -A ; git commit -m "Your Message"` – Rafael Miceli Nov 11 '17 at 11:27
-
I just wanted the modified files. Thus I used `git reset` to undo `git add -A`. – Friedrich -- Слава Україні Aug 10 '20 at 18:52
This command will add and commit all the modified files, but not newly created files:
git commit -am "<commit message>"
From man git-commit
:
-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.

- 6,148
- 6
- 38
- 76

- 5,395
- 2
- 16
- 9
-
129This doesn't actually answer the question, in fact specifically (in bold no less) excludes one of the key parts of the sought for solution. – Arunas Aug 31 '15 at 19:34
-
9
-
5But it covers most typical situation when you commit after "git add -A" and notice that you forgot to change something small in code. I hate to write the same commit message several times from the scratch – KorbenDallas Dec 15 '16 at 09:37
-
1but the thread starter says ALL FILES, so, I think this one does not count – Frederick G. Sandalo Feb 08 '17 at 02:31
-
And also you can add shortcuts for basic git commands in your .bashrc: alias gpl='git pull' alias gps='git push' alias gc='git commit' alias gs='git status' alias gd='git diff' alias ga='git add' alias gck='git checkout' alias gb='git branch' alias gl='git log' alias lcp='git format-patch -1 HEAD' alias resetToMaster='git reset --hard origin/master' – ni3 Apr 03 '17 at 08:10
Not sure why these answers all dance around what I believe to be the right solution but for what it's worth here is what I use:
1. Create an alias:
git config --global alias.coa '!git add -A && git commit -m'
NOTE: The !
preceding the git add -A
command is required for this to work. You can read about why, and more on Git aliases here: git-scm.com | 2.7 Git Basics - Git Aliases
2. Add all files & commit with a message:
git coa "A bunch of horrible changes"
NOTE: coa
is short for commit all and can be replaced with anything your heart desires

- 796
- 9
- 19

- 1,223
- 9
- 14
I use this function:
gcaa() { git add --all && git commit -m "$*" }
In my zsh config file, so i can just do:
> gcaa This is the commit message
To automatically stage and commit all files.

- 406
- 4
- 8
-
1for bash-like `function gcaa() { git add --all && git commit -m "$*" && git push } ` – Damilola Jan 25 '18 at 08:26
-
2@Damilola - what do you mean by *bash-like*? the syntax in the answer works in bash as well – Eliran Malka Jun 24 '19 at 13:45
One-liner to stage ALL files (modified, deleted, and new) and commit with comment:
git add --all && git commit -m "comment"
http://git-scm.com/docs/git-add
http://git-scm.com/docs/git-commit

- 173,523
- 149
- 402
- 512
Committing in git can be a multiple step process or one step depending on the situation.
This situation is where you have multiple file updated and wants to commit:
You have to add all the modified files before you commit anything.
git add -A
or
git add --all
After that you can use commit all the added files
git commit
with this you have to add the message for this commit.

- 357
- 3
- 11
If you just want a "quick and dirty" way to stash changes on the current branch, you can use the following alias:
git config --global alias.temp '!git add -A && git commit -m "Temp"'
After running that command, you can just type git temp
to have git automatically commit all your changes to the current branch as a commit named "Temp". Then, you can use git reset HEAD~
later to "uncommit" the changes so you can continue working on them, or git commit --amend
to add more changes to the commit and/or give it a proper name.

- 45,670
- 22
- 127
- 172
Run the given command
git add . && git commit -m "Changes Committed"
However, even if it seems a single command, It's two separate command runs one by one. Here we just used &&
to combine them. It's not much different than running
git add .
and git commit -m "Changes Committed"
separately. You can run multiple commands together but sequence matters here. How if you want to push the changes to remote server along with staging and commit you can do it as given,
git add . && git commit -m "Changes Committed" && git push origin master
Instead, if you change the sequence and put the push
to first, It will be executed first and does not give desired push after staging and commit just because it already ran first.
&&
runs the second command on the line when the first command comes back successfully, or with an error level of 0. The opposite of &&
is ||
, which runs the second command when the first command is unsuccessful, or with an error level of 1.
Alternatively, you can create alise as git config --global alias.addcommit '!git add -a && git commit -m'
and use it as git addcommit -m "Added and commited new files"

- 8,453
- 9
- 58
- 81
I have in my config two aliases:
alias.foo=commit -a -m 'none'
alias.coa=commit -a -m
if I am too lazy I just commit all changes with
git foo
and just to do a quick commit
git coa "my changes are..."
coa stands for "commit all"

- 143,130
- 81
- 406
- 459

- 16,555
- 7
- 56
- 102
-
10I would hate to work with a repository filled with commit messages saying "none", and I'd reject any PR's on that basis as well. Unfortunately, the only way you can learn the importance of having good commit messages is when you have to go back to audit something written a long time ago ("this line is causing a bug... why was it even added, and will anything break if I change/remove it?"). – gregmac Sep 14 '15 at 17:01
-
1Commits with "none" are never intended to stay for long. Normally I start my own feature branch, do micro commits and squash them into something more reasonable before a merge. Obviously people who do commits for each modified function and do not mind a full blown git log do not need this. – SystematicFrank Sep 14 '15 at 20:30
-
1I use 'wip' (short for "work in progress") instead of 'none' for this purpose and I only push such commits to my private branches. – Sergej Koščejev Jan 11 '16 at 16:53
-
It's still unhelpful, because eventually those "wip" or "none" commits will make it into a branch that other people see, and will pollute the message log. If you're squashing all of your commits before you push then that would be acceptable but it's otherwise still annoying for the team. – Jordan Mar 22 '16 at 21:15
-
-
A lot of people (unfortunately) use version control as a journaling file system and don't write commit messages (or use some useless generic ones). This makes it very hard for others to work on the code in the future. – Peter Mortensen Oct 05 '19 at 18:56
Great answers, but if you look for a singe line do all, you can concatenate, alias and enjoy the convenience:
git add * && git commit -am "<commit message>"
It is a single line but two commands, and as mentioned you can alias these commands:
alias git-aac="git add * && git commit -am "
(the space at the end is important) because you are going to parameterize the new short hand command.
From this moment on, you will be using this alias:
git-acc "<commit message>"
You basically say:
git, add for me all untracked files and commit them with this given commit message.
Hope you use Linux, hope this helps.

- 956
- 13
- 27
I think this is the most elegant way to stage and commit all changes:
git commit -am "message"

- 1,278
- 14
- 23
You can write a small script (look at Ian Clelland's answer) called git-commitall
which uses several git commands to perform what you want to do.
Place this script in your anywhere in your $PATH
. You can call it by git commitall
... very handy!
Found here (question and all answers unfortunately deleted, only visible with high reputation)
Here is a shell script which does a somewhat close thing. Currently it doesn't commit newly added files (it should be easy to add this feature), but it does commit everything else. Also, it visits Git submodules recursively. The intended usage scenario is as simple as
$ git powercommit

- 896
- 9
- 21
The simplest way is to use the following command to add
and commit
the changes with one command:
git commit -a -m "your commit message"
CAUTION: This will not commit untracked files

- 630
- 7
- 25
-
1
-
1@Friedrich thanks, I forgot to mention that. The answer is now updated – Meet Bhalodiya Jan 27 '23 at 07:11