0

I have a folder called migrations and inside that folder it has few python files which looks like this:

migrations/
          __init__.py
          0001_auto_20210203_1910.py
          0002_auto_20210203_1910.py
          0003_auto_20210203_1910.py

What I want to is to push migrations folder with __init__.py to my github and ignore other python files.

This is what i'm doing by following this question Make .gitignore ignore everything except a few files:

migrations/*
!migrations/__init__.py

But it doesn't work as expected. What should I write in my .gitignore?

Thanks

  • 1
    What does "it doesn't work as expected" mean? – matt Feb 17 '21 at 03:29
  • 1
    `.gitignore` only applies to untracked files. Is there any reason you can't simply ignore the `migrations` folder and add `migration/__init__.py` manually? – Brian61354270 Feb 17 '21 at 03:30
  • it commited all files inside `migrations` folder but i only want `__init__.py` to be commited – Kimhong Muong Feb 17 '21 at 03:31
  • 1
    @KimhongMuong If you already _committed_ those files to your repo, modifying `.gitignore` will have no effect. – Brian61354270 Feb 17 '21 at 03:32
  • 3
    I repeat, what does "it doesn't work as expected" mean? Tell us what you do, what happens as a result, what you thought would happen. – matt Feb 17 '21 at 03:42

1 Answers1

0

Not sure is this the best solution but i need to have 2 .gitignore files. One inside my root directory and another one inside migrations directory. All i need to put inside migrations/.gitignore is:

/*
!__init__.py