Cannot remove folder from push

I’m in a bit of a bind.

I started a repository on Github and am trying to push some previously written code to the website. However, the venv folder (which contains my python virtual environment) is included when I push. Git throws an error about how the remote rejected the push because a files in the venv folder was too big.

I added a ‘.gitignore’ file, adding the line ‘venv/*’. I also ran:

git rm --cached venv

When I try to push, the initial error still remains. For some reason, the venv folder still appears to be included when I push. So for some reason, I must have not removed the folder effectively from the push. I’ll just take a look at the list of files that are being committed:

$ git remote
origin

$ git branch
* master


$ git diff --stat --cached origin/master
 .gitignore | 12 +++++
 AngularPropagateCPU.py | 77 +++++++++++++++++++++++++++++
 AngularPropagateTensorflowCPU.py | 75 ++++++++++++++++++++++++++++
 compare.py | 104 +++++++++++++++++++++++++++++++++++++++
 tensorflowTests.py | 11 +++++
 5 files changed, 279 insertions(+)

Wait! ‘venv’ isn’t even listed! So how does it get pushed?

Here is my code folder: https://drive.google.com/file/d/11kWxEbNaFGZr8oobflu3Tw_i7hh3H0D9/view?usp=sharing

Here is the output I get now when I try to push:

$ git push
Enumerating objects: 6794, done.
Counting objects: 100% (6794/6794), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4882/4882), done.
Writing objects: 100% (6793/6793), 106.46 MiB | 2.49 MiB/s, done.
Total 6793 (delta 1541), reused 6773 (delta 1533)
remote: Resolving deltas: 100% (1541/1541), done.
remote: warning: File venv/lib/python3.7/site-packages/numpy/.dylibs/libopenblasp-r0.3.7.dylib is 60.48 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 1429e250b29a39a6d89c33987c10ac2c
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File venv/lib/python3.7/site-packages/tensorflow_core/python/_pywrap_tensorflow_internal.so is 314.06 MB; this exceeds GitHub's file size limit of 100.00 MB
To https://github.com/JamesWhitehead5/AngularPropagateTensorflow.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/JamesWhitehead5/AngularPropagateTensorflow.git'

Here is the git log:

$ git log
commit 962ef380aed9fd59e82335395db3ddb9f4d36d42 (HEAD -> master)
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 28 11:39:49 2019 -0800

    same

commit e782a9613e9ddf5069cb99f2cf4b175475b9617f
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 28 11:36:39 2019 -0800

    added gitignore

commit 9b8abf185a0df43adf6cd7e4477c1cd8f30504c1
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 21 17:01:16 2019 -0800

    try again;

commit 65b238d294d512dc0ff98e19bb62eb4703d8b06d
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 21 16:55:36 2019 -0800

    Removed all files that are in the .gitignore

commit b5955f28ee377124f0ac1ec92cf1cc123d073833
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 21 16:54:36 2019 -0800

    Try to omit venv again

commit 899fa35686fe8f0bbdf2fcd66c09f06d075dc99f
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 21 16:43:37 2019 -0800

    Added gitignore for tracking

commit 962ef380aed9fd59e82335395db3ddb9f4d36d42 (HEAD -> master)
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 28 11:39:49 2019 -0800

    same

commit e782a9613e9ddf5069cb99f2cf4b175475b9617f
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 28 11:36:39 2019 -0800

    added gitignore

commit 9b8abf185a0df43adf6cd7e4477c1cd8f30504c1
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 21 17:01:16 2019 -0800

    try again;

commit 65b238d294d512dc0ff98e19bb62eb4703d8b06d
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 21 16:55:36 2019 -0800

    Removed all files that are in the .gitignore

commit b5955f28ee377124f0ac1ec92cf1cc123d073833
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 21 16:54:36 2019 -0800

    Try to omit venv again

commit 899fa35686fe8f0bbdf2fcd66c09f06d075dc99f
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 21 16:43:37 2019 -0800

    Added gitignore for tracking

commit 22d224ca30084ed2bab484ac53800bb6b7858129
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 21 16:39:52 2019 -0800

    Removed tracking for venv

commit f34e4921a020b199b06826b32471f365b1568961
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Sat Dec 21 16:34:43 2019 -0800

    Placed venv into gitignore

commit 347dfe80e543ce7a0d6359ddd8b60af0f6c974cf
Author: jameswhitehead <james.whitehead490@gmail.com>
Date: Mon Dec 16 11:47:53 2019 -0800

    Functional equivalent of propagator made in tensorflow

commit a8605e9389d9cb63cf24614843659e683ab7b561 (origin/master, origin/HEAD)
Author: James Whitehead <43419285+JamesWhitehead5@users.noreply.github.com>
Date: Sat Dec 14 10:54:16 2019 -0800

    Initial commit

I found a thread that has a similar problem:

https://github.community/t5/How-to-use-Git-and-GitHub/Git-wants-to-push-files-that-don-t-even-exist/td-p/26225

I managed to resolve this by:

$rm -rf .git

$git init
Initialized empty Git repository in <redacted>/AngularPropagateTensorflow/.git/

$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.gitignore
	AngularPropagateCPU.py
	AngularPropagateTensorflowCPU.py
	README.md
	compare.py
	tensorflowTests.py

nothing added to commit but untracked files present (use "git add" to track)

$git add .

$git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file: .gitignore
	new file: AngularPropagateCPU.py
	new file: AngularPropagateTensorflowCPU.py
	new file: README.md
	new file: compare.py
	new file: tensorflowTests.py

$git commit -m "Initial commit"

$git remote add origin git@github.com:JamesWhitehead5/AngularPropagateTensorflow.git

$git remote -v
origin	git@github.com:JamesWhitehead5/AngularPropagateTensorflow.git (fetch)
origin	git@github.com:JamesWhitehead5/AngularPropagateTensorflow.git (push)

$git pull origin master
From github.com:JamesWhitehead5/AngularPropagateTensorflow
 * branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories


$git pull --allow-unrelated-histories origin master
$git push --set-upstream origin master

Since venv is a directory, next time you run into this you can pass git rm -r --cached venv/ -f and that will remove that environment directory from git, but not delete it.

Then you can of course add that dir to your .gitignore

There’s also preload ignores for multiple languages when creating a repository!