Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make .gitignore configurable based on environment variables?

Is it possible to add to .gitignore rules depends on environment variables?

for example

if -e $(ENV_VAR) "AAA"
!liba.so
else
liba.so

Basically what I want is to have a repository such that if ENV_VAR = "AAA" the local repository will have a.txt and if ENV_VAR isn't set the a.txt will be removed.

like image 839
0x90 Avatar asked Oct 21 '25 02:10

0x90


2 Answers

The answer is no. Gitignore rules are static. You can turn around it by dynamically creating your .gitignore file. So, you will also have dynamically created static rules.

This can be easily done within the application building system such a Makefile. The .gitignore file can rebuilt each time the project is built.

Example Makefile:

all: my_app .gitignore

.gitignore: some deps
    cp my_static_gitignore_rules .gitignore
    echo 'dynamically_created_rule1' >> .gitignore
    echo 'dynamically_created_rule2' >> .gitignore

my_app: my_app.c
    ...
like image 84
jonasmike Avatar answered Oct 23 '25 18:10

jonasmike


Currently the answer is no Yes, but not using an environment variable.

My use case is simple; I'd like to avoid accidentally checking in changes that I've made to a specific file so I can run my code locally.

Let's say I add my super secret password to the src/assets/secrets.xml file so that I can run my code locally, but I never want my password to leak to github so it can be found with tools like this.

Originally I thought having the ability to export GITIGNORE=path/to/that/file would be helpful in this circumstance.

But since that's not an option, here's how to accomplish the same goal.

git update-index --assume-unchanged src/assets/secrets.xml

To undo this effect:

git update-index --no-assume-unchanged src/assets/secrets.xml

After re-reading the OP's question a couple of times, I'm not sure if this will do what he's asking.

like image 20
JohnnyLambada Avatar answered Oct 23 '25 19:10

JohnnyLambada