git ignore not ignoring a file when using GCloud's gcloudignore

580 views Asked by At

I have a rule to ignore secret.py (production.py in my case) and once I added .gcloudignore, github stopped following that rule... Is there some sort of a rule overriding between gitignore and gcloudignore that I am not aware of?

my-project/
    .git
    .gitignore
    my-project/
        .gcloudignore
        settings/
            base.py
            local.py
            production.py

my .gitignore:

my-project/my-project/settings/production.py
my-project/my-project/settings/local.py

my .gcloudignore:

# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
#   $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

*.sqlite3
settings/local.py

End result is that the 'local.py' is NOT pushed to google cloud NOR github. However, 'production.py' IS pushed to github AND gcloud.

2

There are 2 answers

0
Myk Willis On BEST ANSWER

If you had previously (perhaps accidentally) submitted a change to git that included my-project/my-project/settings/production.py, then it will remain a part of the repository even if it is subsequently added to .gitignore.

Assuming you are at the root of your project, you can use

$ git log my-project/my-project/settings/production.py

to see its git history. If it is present in your repo, you can do

$ git rm --cached my-project/my-project/settings/production.py

to remove it from the repo, but keep it in your local (working) environment.

1
Afelaia Timur On

Looks like you are enforcing to ignore the rules applied before.

Though make sure that the cloudignore is enable via

gcloud config set gcloudignore/enabled true

And make sure to place .gcloudignore - > in the root of your project / basically where you .git .gitignore reside.