How can I stage and commit all files, including newly added files, using a single command?

Git

Git Problem Overview


How can I stage and commit all files, including newly added files, using a single command?

Git Solutions


Solution 1 - Git

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).

Solution 2 - Git

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.

Solution 3 - Git

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'
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

Solution 4 - Git

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.

Solution 5 - Git

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

Solution 6 - Git

Committing in git can be a multiple step process or one step depending on the situation.

  1. 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
    
  2. After that you can use commit all the added files

    git commit
    

    with this you have to add the message for this commit.

Solution 7 - Git

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.

Solution 8 - Git

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"

Solution 9 - Git

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"

Solution 10 - Git

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.

Solution 11 - Git

I think this is the most elegant way to stage and commit all changes:

git commit -am  "message"

Solution 12 - Git

try using:

git add . && git commit -m "your message here"

Solution 13 - Git

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)

Solution 14 - Git

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnantha KumaranView Question on Stackoverflow
Solution 1 - GitIan ClellandView Answer on Stackoverflow
Solution 2 - GitJai KeerthiView Answer on Stackoverflow
Solution 3 - GitthefinnomenonView Answer on Stackoverflow
Solution 4 - GitphlppnView Answer on Stackoverflow
Solution 5 - GitYarinView Answer on Stackoverflow
Solution 6 - GitKing LinuxView Answer on Stackoverflow
Solution 7 - GitAjedi32View Answer on Stackoverflow
Solution 8 - GitKiran ManiyaView Answer on Stackoverflow
Solution 9 - GitSystematicFrankView Answer on Stackoverflow
Solution 10 - GitVeRoView Answer on Stackoverflow
Solution 11 - GitK.AmanovView Answer on Stackoverflow
Solution 12 - GitPhotonView Answer on Stackoverflow
Solution 13 - GittanasciusView Answer on Stackoverflow
Solution 14 - GitGrwlfView Answer on Stackoverflow