Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force add despite the .gitignore file

Tags:

git

gitignore

Is there a way to force git to add a file despite the .gitignore file?

like image 677
Mark Avatar asked Nov 04 '11 08:11

Mark


People also ask

How do I force add an ignored file in git?

The git add command can be used to add ignored files with the -f (force) option.

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 you force Add all files in git?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area. We also say that they will be staged.


2 Answers

See man git-add:

   -f, --force        Allow adding otherwise ignored files. 

So run this

git add --force my/ignore/file.foo 
like image 62
Daniel Böhmer Avatar answered Oct 11 '22 09:10

Daniel Böhmer


Despite Daniel Böhmer's working solution, Ohad Schneider offered a better solution in a comment:

If the file is usually ignored, and you force adding it - it can be accidentally ignored again in the future (like when the file is deleted, then a commit is made and the file is re-created.

You should just un-ignore it in the .gitignore file like this: Unignore subdirectories of ignored directories in Git

like image 28
A-S Avatar answered Oct 11 '22 08:10

A-S