Git stage and commit with one command

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"

  • How to move a git repository into another directory and make that directory a git repository?
  • Enforcing coding style and being warning and lint-free across teams in Android Studio or git/github
  • Get back the changes after accidental checkout?
  • Daily and weekly backup strategies
  • Does GitHub support git:// protocol for pull?
  • Removing files using Git GUI
  • Simultaneous Git Pull On Same Server & Directory & User
  • git push says Everything up to date
  • mass-change email addresses on git with github
  • Line-endings in go-language source files using vim and git on MS-Windows
  • Does a git commit hash equal a repository state?
  • How to prevent git vimdiff from opening files as read-only?
  • 4 Solutions collect form web for “Git stage and commit with one command”

    git commit -a ... will automatically add and commit files that have already been commited previously and are modified or deleted now. As you found out it does not affect new files.

    You could use an alias to combine the git add ... and git commit ... into one command line. But if you do, take the time to script it to not need to use git add . or git add -A as that will inevitably lead to commiting files you really don’t want to.

    You can do this by using an alias.

    Define an alias like this:

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

    Then you can use it like a normal git command: git your-alias -m 'commit message'

    What you want to do is:

    git commit -am "Message for my commit"

    This will automatically add everything and you can type your message in one command.
    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.”

    Use the given as the commit message. If multiple -m options are given, their values are concatenated as separate paragraphs.”

    If you want to stage and commit untracked files, you can:

    git add -A & git commit -am 'message'
    if [ -z "$1" ]; 
        then echo "Please supply a commit message wrapped in single quotes '' before you proceed!"; 
        cd /opt/lampp/htdocs/namOfProject/
        git add *
        git commit -am "$1"
        git push;

    I normally use a simple shell script that runs everything in one clean sweep. Save the script anywhere you like and give it a name like

    Then, and this is important, make the file executable as follows:

    chmod +x ./

    Run this as follows on your terminal:

    ./ 'Your commit's description'

    Explaining the script

    1. First line just checks that there’s a description for your commit. It is passed it as an argument on the command line.

    2. The fourth line changes into your project’s directory.

    3. Then you’ll stage your changes and commit them with the argument that you passed in.

    4. Finally, the second last line will push the changes to your remote repository

    Git Baby is a git and github fan, let's start git clone.