How do I push files specified in .gitignore?
Asked Answered
B

4

10

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?

Bethelbethena answered 3/8, 2012 at 1:55 Comment(3)
"that will receive that directory anyway" - sorry, what do you mean? a directory is either ignored or not...Mariquilla
It may be that it's fundamentally not possible. In which case, feel free to answer my question saying as much if you're positive of it :)Bethelbethena
I'm not 100% sure what you're after. I've posted an answer with some possibilities from other SO Qs. If that's not quite what you're after, let us knowMariquilla
M
8

I think the functionality you're looking for can be achieved by having a branch used to deploy to your Cloud Provider.

Setup a dev branch which includes your .gitignore file, check your incremental work into that branch.

Merge your dev branch into your deploy branch which doesn't contain a .gitignore file but contains the vendors directory.

once you've completed your merge, push to the deployment remote from your deploy branch.

Mcnulty answered 3/8, 2012 at 5:10 Comment(1)
best solution for this I have heard recommended to date. thanksSpurgeon
K
10

Your .gitignore file has nothing to do with pushing. It is used by things like git status and git add to figure out what files should be (or could be) part of a future commit. You can add things that are ignored using the git add command; it will throw an error unless you use the -f option:

The following paths are ignored by one of your .gitignore files:
somefilename
Use -f if you really want to add them.
fatal: no files added

Once you've added the file to the repository, it will be pushed along with any other changes.

Kc answered 3/8, 2012 at 2:3 Comment(2)
Problem is, I don't want to commit this directory to my repo, I only want it to be included on a push to a specific remote (appfog). In this case, it's a directory with automatically managed dependencies.Bethelbethena
That's fine, but it is still the case that the .gitignore file does not control what gets pushed where.Kc
M
8

I think the functionality you're looking for can be achieved by having a branch used to deploy to your Cloud Provider.

Setup a dev branch which includes your .gitignore file, check your incremental work into that branch.

Merge your dev branch into your deploy branch which doesn't contain a .gitignore file but contains the vendors directory.

once you've completed your merge, push to the deployment remote from your deploy branch.

Mcnulty answered 3/8, 2012 at 5:10 Comment(1)
best solution for this I have heard recommended to date. thanksSpurgeon
I
2

use -f to forcefully add.

Here is the example.

git add -f path/to/file
Ima answered 24/1, 2022 at 12:1 Comment(0)
I
0

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.

Iams answered 13/5, 2022 at 21:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.