How to commit a file without staging it in git

Posted in Articles

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

For simple scenarios, you can save a bit of typing by committing modified files in git without needing to explicitly stage them first.

Suppose you are constantly changing a file (such as app.js) and constantly needing to push it to cloud hosting (such as Heroku). ¬†You would likely be doing …

git add .
git commit -m “another version”
git push heroku master

You actually can skip the “git add” command which would put files to stage if you go with the -a flag in the commit command like …

git commit -a -m “another version”
git push herkoku master

For example, if a git status shows some modified unstaged files …

git status
On branch master
Changes not staged for commit:
modified: app.js

If you run …

git commit -a -m “another version”

And then run git status, it will show that the modified file has been staged and committed all in one step…

git status
nothing to commit, working directory clean