2

When I used git add * it's skipping some files and folders. But the same command git add * is working perfectly for some other project. But when I'm using git add -f * is working fine.

Eje
  • 354
  • 4
  • 8
Kodali444
  • 1,283
  • 1
  • 17
  • 21
  • https://git-scm.com/docs/git-add#git-add--f – axiac Nov 18 '17 at 12:31
  • 1
    location where git is executed is important. projects may have different ignore files, which is used by git for filtering trivial files or folders. be aware that git add works with relative path. -f or --force allows adding otherwise ignored files. see: https://git-scm.com/docs/git-add – icaptan Nov 18 '17 at 12:38

4 Answers4

3

Okay, this is from the Git Reference Manual ref https://git-scm.com/docs/git-add:

The git add command will not add ignored files by default. If any ignored files were explicitly specified on the command line, git add will fail with a list of ignored files. The git add command can be used to add ignored files with the -f (force) option.

Eje
  • 354
  • 4
  • 8
Daniel Kaas
  • 111
  • 8
2

In git add * the * is interpreted by the shell, and has nothing to do with Git. If your shell is Bash, files and directories starting with . will not be matched by * (by default), so they will not be passed to git add, and will not get added to the index.

Instead of git add *, if you want to add all files in the current directory, including the ones starting with ., it's better to use git add ..

Also, as other answers pointed out, git add will not add files that are marked to be ignored. You can force adding such files using -f, but most probably you don't want to do that, there are very few legitimate use cases of this flag.

A very valuable comment by @torek:

Worth noting: if git add * is being run in a Windows non-bash interpreter, the * is passed literally to git add, at which point Git, not the shell, interprets the *. In this case files and directories whose names start with . will get added. One can simulate this on a Linux or similar system by running git add '*', though there is no reason to bother (other than demonstration) since git add . is just as effective.

janos
  • 120,954
  • 29
  • 226
  • 236
  • 1
    Worth noting: if `git add *` is being run in a Windows non-bash interpreter, the `*` is passed literally to `git add`, at which point Git, not the shell, interprets the `*`. In this case files and directories whose names start with `*` *will* get added. One can simulate this on a Linux or similar system by running `git add '*'`, though there is no reason to bother (other than demonstration) since `git add .` is just as effective. – torek Nov 18 '17 at 15:51
0

git add man page:

The git add command will not add ignored files by default. If any ignored files were explicitly specified on the command line, git add will fail with a list of ignored files. Ignored files reached by directory recursion or filename globbing performed by Git (quote your globs before the shell) will be silently ignored. The git add command can be used to add ignored files with the -f (force) option.

Nonika
  • 2,490
  • 13
  • 15
0

The attribute "-f" or "--force" coming after "git add" command means that you are forcing the adding to the stagging area ignored files ( which mean that these files are going to be a part of the next commit)

So the difference between "git add * " and "git add -f " means that in the first case you add all the files () excepted the ignored files, and in the second case you add all the files (and you force git to add the ignored files which are notified in the .gitignore file)

source : https://git-scm.com/docs/git-add#git-add--f

marcdahan
  • 2,654
  • 25
  • 25