Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git stage and commit with one command

Tags:

git

Is there a way in Git to stage and commit files in one command? For example in my local repository I created files index.html, styles.css located in css folder and script.js located in js folder. Now I want to run one command to stage and commit all this files. I tried code below but it didn't work

git commit -a -m "my commit message" 
like image 998
Dmitry Avatar asked Feb 11 '13 16:02

Dmitry


People also ask

How do you do add and commit in one command?

Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.


1 Answers

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' 
like image 123
David Hunsicker Avatar answered Sep 30 '22 15:09

David Hunsicker