3

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.

2
  • git-scm.com/docs/git-add#git-add--f Commented Nov 18, 2017 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: git-scm.com/docs/git-add Commented Nov 18, 2017 at 12:38

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

What happens on the next commit? Will the previously ignored files not be ignored anymore, or will they now be added, because they were forced in a previous commit?
@MaxCascone Once a file is tracked it will stay tracked, at least until you manually remove it from the index, see stackoverflow.com/q/1274057/2398020
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.

1 Comment

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.
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.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.