1

given an existing repo, I want to (re)init it from scratch, i.e., delete all its history and push it to the server (here, GitHub). Since GitHub has a hard 100MB file size limit and the folder contains various very large files, I cannot simply perform an git add .. What would be an easy way that does not involve manually gathering a list of all these large files?

My idea would be to invoke the following commands (taken from https://gist.github.com/stephenhardy/5470814) but as said above, the gid add . seems infeasible in this case.

-- Remove the history from 
rm -rf .git

-- recreate the repos from the current content only
git init
git add . # <-- without large files!
git commit -m "Initial commit"

-- push to the github remote repos ensuring you overwrite history
git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
git push -u --force origin master
pedjjj
  • 958
  • 3
  • 18
  • 40
  • 4
    Does this answer your question? [Git -- add all files that are smaller than X megabytes](https://stackoverflow.com/questions/22057331/git-add-all-files-that-are-smaller-than-x-megabytes) – Kamol Hasan Jun 09 '20 at 16:26

1 Answers1

3

In my knowledge, git-add doesn't propose filtering based on the size. You may be able to achieve what you want by adding those files to your .gitignore automatically, for example using this solution https://stackoverflow.com/a/5200267/7053790:

find . -size +1G | cat >> .gitignore

Obviously, replace the +1G by a sensible value for you.

If possible in your situation, you can also put all the big files in one directory, or in multiple directories with the same name, and ignore those directories. For example:

.
├── data/
├── file.py
└── subdir1/
    ├── data/
    └── myfile.php

You can put ./*data in the gitignore, which will ignore all data directories

chepner
  • 497,756
  • 71
  • 530
  • 681
Battleman
  • 392
  • 2
  • 12
  • 1
    Alternatively, `find . -size -1G -exec git add {} +`. – chepner Jun 09 '20 at 16:31
  • 1
    This is very close to the accepted answer in the linked duplicate. A refinement there, noted in a comment, is to use `*` instead of `.` to avoid selecting files in the `.git` subdirectory. – Caleb Jun 09 '20 at 16:36