Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit -am does not work on initial commit. Why?

Tags:

git

Why does git commit -am not work on my initial commit, but works thereafter?

$ touch test.txt
$ ls -a
.  ..  .git  test.txt
$ git commit -am "Initial commit"
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       test.txt
nothing added to commit but untracked files present (use "git add" to track)
$
like image 512
Anthony Avatar asked Jan 13 '23 12:01

Anthony


1 Answers

You have to first git add your file to the repo. git commit only commits changes to tracked files, git commit -a will commit all changes to tracked files. But untracked files will not be committed at any point.

You'll find that even on commits after the initial, if you create a new file it will not be committed with git commit -a until you git add it.

like image 107
tpg2114 Avatar answered Jan 16 '23 01:01

tpg2114