2

I have a folder containing a bunch of git repositories. I would like to create a back up of this folder, but the problem is that if I just copy everything (recursively e.g. using cp -r <folder>) the resultant folder is huge. This is because each repo has git ignored files/folders that are large in size (e.g. virtual environments, data files) that I do not want to back up. All repos are small in size otherwise.

Is there a way to recursively copy a folder but only include non-gitignored files/folders? Ideally I'd like to include the .git folders to store all commit/branch history as well.

1 Answer 1

1
  1. Backup != repo-copy. You have to select only one form
  2. If you want backup(s) (snapshot of some tree without history), you have to read about git archive and use it, for each git-repo separately
  3. If you want "copy with history" just git clone each repo (and regularly git pull later)
3
  • Okay, but what if I want to copy a repo into a docker image when building it? But without the parts in .gitignore and I don't need the git history.
    – grofte
    Feb 21, 2023 at 12:01
  • @grofte In your question you said you wanted .git as well but here you say that you don’t need the Git history? Apr 30, 2023 at 11:18
  • Ah, no I meant whether I could use the .gitignore file when building a docker image. Instead of explicitly writing what to copy in the dockerfile. It's tangentially related because the original was asking for a bash command. But tbh it is probably better and safer to be explicit in the dockerfile.
    – grofte
    May 2, 2023 at 11:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .