10

Is it possible to have git commit also add new files and directories?

It seems a lot of needless typing in the long run to have to type git add . then git commit

(That, and I have a tendency to often forget to call git add . resulting in versions with missing directories and such)

ina
  • 19,167
  • 39
  • 122
  • 201
  • if you use a IDE from Jetbrais you will have a list of unversioned files. You will still have to add and commit, but atleast you have a visual list. – Ben Jan 21 '12 at 20:45
  • would `git commit -a` do what you need? – Martin York Jan 21 '12 at 20:48
  • git commit -a does not seem to stage the new files.. i've been using that but the new directories and files were not added automatically – ina Jan 21 '12 at 21:02
  • @BenjaminUdinktenCate - but Jetbrains does not support very many languages, so it would be nice if there were some one line terminal command for this – ina Jan 21 '12 at 21:02

1 Answers1

15

As long as I am informed right there is no such command (It could be dangerous when you have debug-files containing passwords), but if you want to simulate you could add this alias to your git config:

git config --global alias.commitx "!git add . && git commit"

Using git commitx will now run git add . followed by git commit, so you can do

git commitx -m "testing commitx on new unstaged files"
Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
TimWolla
  • 31,849
  • 8
  • 63
  • 96
  • this seems like it's the trick... do i just type this into the terminal to set it up: `git config alias.commitx=!git add . && git commit -a -m` – ina Jan 21 '12 at 21:05
  • 3
    @ina: The command would be `git config --global alias.commitx '!git add . && git commit -a -m'` - you have to quote the command to keep bash from interpreting it, and `git config` (the command) doesn't use `=` in its syntax, just ` ` as separate arguments. – Cascabel Jan 22 '12 at 01:37
  • Thanks guys - this is very helpful... collectively, among me + the users who google this up, you've probably saved gazillions of microseconds already! :-) – ina Jan 23 '12 at 07:02