Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping `__pycache__` out of my repository when adding/committing from pythonanywhere

I built a web app on a my local win7 machine. I did it with pycharm and used git as version control. I'm a total git novice.

I put the repository on github so that I could stage the webapp to my pythonanywhere server.

On pythonanywhere side, I did some small edits to various files. I wanted to commit these changes back to the repository.

(udemy) 10:44 ~/keystone (master)$ git commit -m "got it running on pythonanywhere staging"
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
        modified:   keystone/settings/base.py
        modified:   keystone/settings/local_postgres.py
        modified:   keystone/settings/staging_straits.py
        deleted:    p0150_1.pdf
Untracked files:
        crapboard/__pycache__/
        crapboard/migrations/__pycache__/
        crapboard/templatetags/__pycache__/
        keystone/__pycache__/
        keystone/settings/__pycache__/
no changes added to commit

There were three modified files and one deletion that I wanted to commit to the repository.

so I did

(udemy) 14:03 ~/keystone (master)$ git add --all
(udemy) 14:03 ~/keystone (master)$ git commit -m "staged to pythonanywhere"
[master ac6bb7e] staged to pythonanywhere
 27 files changed, 23 insertions(+), 115 deletions(-)
 create mode 100644 crapboard/__pycache__/__init__.cpython-36.pyc
 create mode 100644 crapboard/__pycache__/admin.cpython-36.pyc
 create mode 100644 crapboard/__pycache__/apps.cpython-36.pyc
 create mode 100644 crapboard/__pycache__/forms.cpython-36.pyc
 create mode 100644 crapboard/__pycache__/models.cpython-36.pyc
 create mode 100644 crapboard/__pycache__/pdf_views.cpython-36.pyc
 create mode 100644 crapboard/__pycache__/urls.cpython-36.pyc
 create mode 100644 crapboard/__pycache__/views.cpython-36.pyc
 create mode 100644 crapboard/migrations/__pycache__/0001_initial.cpython-36.pyc
 create mode 100644 crapboard/migrations/__pycache__/0001_squashed_0005_auto_20170921_2154.cpython-36.pyc
 create mode 100644 crapboard/migrations/__pycache__/0002_auto_20170909_1137.cpython-36.pyc
 create mode 100644 crapboard/migrations/__pycache__/0003_auto_20170912_2029.cpython-36.pyc
 create mode 100644 crapboard/migrations/__pycache__/0004_problem_author.cpython-36.pyc
 create mode 100644 crapboard/migrations/__pycache__/0005_auto_20170921_2154.cpython-36.pyc
 create mode 100644 crapboard/migrations/__pycache__/__init__.cpython-36.pyc
 create mode 100644 crapboard/templatetags/__pycache__/__init__.cpython-36.pyc
 create mode 100644 crapboard/templatetags/__pycache__/crapboard_filters.cpython-36.pyc
 create mode 100644 keystone/__pycache__/__init__.cpython-36.pyc
 create mode 100644 keystone/__pycache__/urls.cpython-36.pyc
 create mode 100644 keystone/settings/__pycache__/__init__.cpython-36.pyc
 create mode 100644 keystone/settings/__pycache__/base.cpython-36.pyc
 create mode 100644 keystone/settings/__pycache__/settings_secret.cpython-36.pyc
 create mode 100644 keystone/settings/__pycache__/staging_straits.cpython-36.pyc
 rewrite keystone/settings/staging_straits.py (65%)
 delete mode 100644 p0150_1.pdf

Argh. It committed all these __pycache__ directories too.

I'm guessing this happened because I should have made some kind of global/general .gitignore file on my pythonanywhere server?

So questions:

1) how do I get rid of this pycache stuff from my repository permanently 2) how do I prevent my pythonanywhere server from trying to add that stuff to my repository in the future -- I do not have this issue with pycharm/local machine -- it ignores those files.

like image 398
user3556757 Avatar asked Sep 26 '17 14:09

user3556757


People also ask

Should you push __ Pycache __?

__pycache__ is among the directories that shouldn't be pushed to remote repositories. Therefore, all you need to do is specify the directory in . gitignore file. Note that for Python projects in general, there are a lot more files that need to go into .

What is Pycache?

__pycache__ is a directory that contains bytecode cache files that are automatically generated by python, namely compiled python, or . pyc , files. You might be wondering why Python, an "interpreted" language, has any compiled files at all.

What goes in a Gitignore file?

A . gitignore file is a text file placed in your git repository that tells git not to track certain files and folders that you don't want being uploaded to your master repository. It has a lot of uses, and you will almost always need to configure it if you're setting up a new repo.


1 Answers

According to git docs, it is simplely to add to ~/.gitignore the following:

**/__pycache__

A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".

like image 74
Nguyen Van Duc Avatar answered Oct 09 '22 10:10

Nguyen Van Duc