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

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

This question is related to git

The answer is


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


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.

try using:

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

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


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.


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.


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"


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)


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.


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"


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.