How do I push files specified in .gitignore?

Viewed 14426

If I have a "vendors" directory in my .gitignore, is there a way I can set up a remote that will receive that directory anyway when I do a push?

4 Answers

use -f to forcefully add.

Here is the example.

git add -f path/to/file

Nishad-up's answer is correct: git commit and git push will only handle the content you set to update to the remote. But when you call git add on something that's in .gitignore, or inside a folder that's listed there, git doesn't accept the command, and throws the error you got.
You have to force staging such files or folders using git add -f relative-path-to/my-file.png or whatever file(s) you want, the rest is the same (git commit, git push, etc).
*I couldn't figure out how to do this through the VS-Code source control bar, I had to do it in the terminal.

Related