Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git add and commit in one command

Tags:

git

Is there any way I can do

git add -A git commit -m "commit message" 

in one command?

I seem to be doing those two commands a lot, and if Git had an option like git commit -Am "commit message", it would make life that much more convenient.

git commit has the -a modifier, but it doesn't quite do the same as doing git add -A before committing. git add -A adds newly created files, but git commit -am does not. What does?

like image 619
Chetan Avatar asked Nov 28 '10 20:11

Chetan


People also ask

When to use git add and commit?

git add : takes a modified file in your working directory and places the modified version in a staging area. git commit takes everything from the staging area and makes a permanent snapshot of the current state of your repository that is associated with a unique identifier.

Can you git add after git commit?

git add. The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit .


1 Answers

You can use git aliases, e.g.

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

and use it with

git add-commit -m 'My commit message' 

EDIT: Reverted back to ticks ('), as otherwise it will fail for shell expansion on Linux. On Windows, one should use double-quotes (") instead (pointed out in the comments, did not verify).

like image 56
Martin C. Avatar answered Oct 01 '22 16:10

Martin C.