Reputation: 9521
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?
Upvotes: 159
Views: 111251
Reputation: 4734
For those using Staged
/Unstaged
views, you can add everything into the Unstaged
area by adding the -N
flag, like this:
git add -N .
Upvotes: 0
Reputation: 3
Mine still include files i told it to ignore, so i did this... i added to gitignore -> " .gitignore " then i tried " git status ", and the file i wanted ignored were ignored.
Upvotes: 0
Reputation: 62881
Another option is to use the Git repo's exclude
file. This file works similar to a .gitignore
file but isn't committed to the repo.
From the Github docs:
You can use this technique for locally-generated files that you don't expect other users to generate, such as files created by your editor.
Use your favorite text editor to open the file called .git/info/exclude
within the root of your Git repository. Any rule you add here will not be checked in, and will only ignore files for your local repository.
.git/info/exclude
exclude
file as you would the .gitignore
fileUpvotes: 6
Reputation: 13763
Try git add .
(which means "add all files in the current directory and below")
Upvotes: 14
Reputation: 13761
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.
Upvotes: 294
Reputation: 8281
git add .
This will add all paths and ignore matches from .gitignore
Upvotes: 35