0

I am using git and most of the time we use this command to add files in our repository. git add . and after that we write a commit message like this git commit -m "add file info.js" . But I came across with this command git commit -am "message". If I have not created a new file this will stage the commit and send the commit with a message.

But If I create a new file like file.js the command does push the latest code on my repository but not the new file. I wonder why. Can somebody please explain me.

Usman Iqbal
  • 2,379
  • 5
  • 26
  • 50
  • 3
    Possible duplicate of [git commit -m vs. git commit -am](https://stackoverflow.com/questions/19877818/git-commit-m-vs-git-commit-am) – CodeCaster Apr 16 '19 at 08:17
  • Please read [ask] and show what you have tried. If you search the web for "git commit "am"", you'll find the linked duplicate as well as the documentation, explaining: _"git commit -a automatically stage **all tracked, modified files** before the commit"_. So it doesn't add new files. – CodeCaster Apr 16 '19 at 08:18

1 Answers1

2

Because some of your files are not staged. This happens when you delete/add files that are not currently being tracked.

-a documentation:

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.

Eventually you would need to do still a git add . when you add/delete files that are not currently being tracked.

denis_lor
  • 6,212
  • 4
  • 31
  • 55