Reputation: 115
I don't want some files to be tracked by git and I'm excluding them with a .gitignore file. but I want to push them to the origin branch because they are necessary when someone clones the project.
Now the question is can I do this without adding and committing the excluded files. I found this answer on StackOverflow. but I guess maybe git has a better solution for this.
Upvotes: 0
Views: 316
Reputation: 30888
Technically it's possible to push one or more files to the remote without committing. Taking an ignored file foo.txt
for example:
git tag xxx $(git hash-object -w foo.txt) -m "Track the content of foo.txt"
git push origin xxx
It creates a tag that points at the blob object that stores the content of foo.txt
, and pushes it to the remote repository. One can fetch the blob through the tag and read the content. However one cannot know how to use the content without extra instruction.
Upvotes: 0
Reputation: 76774
No, there isn't. A file is either tracked by Git, or it is not.
It sounds like you're trying to create some sort of tracked but ignored file, and that isn't possible with Git. The Git FAQ explains why, and suggests this approach for configuration files:
If your goal is to modify a configuration file, it can often be helpful to have a file checked into the repository which is a template or set of defaults which can then be copied alongside and modified as appropriate. This second, modified file is usually ignored to prevent accidentally committing it.
You can do this with a script or as part of your build process, whichever is most appropriate for your project.
Upvotes: 0
Reputation: 317
I summarized your question here:
Is there a way to push specified files in the .gitignore file to origin without adding and committing the excluded files?
Unfortunately, there is not. You can git add --force
the required file and then push it, but that's not what you asked for.
If you're trying to set up a project that requires API keys or other secrets, I recommend including instructions on how to acquire them in a README.md
file in the project.
Upvotes: 2