Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git add all except ignoring files in .gitignore file

I am adding source control to a project that had none. The problem is that there are a lot of files to initially add to git with a .gitignore file, but I can't figure out how to add all files without including the files matching something in the .gitignore file.

git add * 

The above command will not add any files because it detects files which are ignored by the .gitignore.

git add -f * 

The above command will add all files including the files I wish to ignore.

So, how do I add all files while still adhering to the .gitignore file?

like image 221
E-rich Avatar asked Jul 07 '11 14:07

E-rich


People also ask

Does git add ignore Gitignore?

The . gitignore file tells Git which files to ignore when committing your project to the GitHub repository. gitignore is located in the root directory of your repo. / will ignore directories with the name.

How do I Gitignore everything except?

You want to use /* instead of * or */ in most cases The above code would ignore all files except for . gitignore , README.md , folder/a/file. txt , folder/a/b1/ and folder/a/b2/ and everything contained in those last two folders.

Does git add add ignored files?

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.


2 Answers

I think you mean git add . which will add all of the files to the repo that AREN'T specified in the .gitignore - you can see these changes by typing git status

The . in bash usually means this directory and all other directories recursively, so if you do this from the bottom level of your repo, you should add all of the files.

My usual git flow is to create the .gitignore file and add the project files to the repo. I'll test the .gitignore file by typing git status after importing the files - if I see the files that I've added (for example only .php or .html, NOT .mp3 or .mov), then you can git add . to add all, and git commit -m "initial commit" to commit them and you should be set.

like image 91
Nic Avatar answered Oct 12 '22 21:10

Nic


git add . 

This will add all paths and ignore matches from .gitignore

like image 23
Leom Burke Avatar answered Oct 12 '22 22:10

Leom Burke