2

I want to have three copies of a git repository:

  1. A copy on my own laptop
  2. A copy on an external server
  3. A copy on GitHub

The repository will include several GB of binary files, in addition to code and documentation. I'd like to keep everything on my laptop and on the external server, but I would like to exclude the binary files from GitHub since they are both confidential and large. How can I do this?

If it matters, the binary file contents won't change but more binary files will be added in the future, and it's possible that some binary files may be removed. I need the binary files to stay synced between my laptop and the server, and I want to keep backups in case anything is accidentally removed. The best solution I have so far is to add the binary files to .gitignore, use a second program to sync only these files between my laptop and the server, and use a third program to make versioned backups of only these files on the server.

user102162
  • 822
  • 1
  • 8
  • 9
  • You could only push a specific branch to github? – evolutionxbox Feb 07 '18 at 16:41
  • https://stackoverflow.com/questions/29579546/git-excludesfile-for-a-branch/29583813#29583813 ? – user102162 Feb 07 '18 at 16:46
  • No I don't mean excludes. I'm talking about only _pushing_ a specific branch to github. – evolutionxbox Feb 07 '18 at 16:47
  • Is this what you mean? I'd keep a second branch that's identical to the main branch, except without the binary files. Each time I make changes to the code and documentation, I also apply the commit to the second branch, and push the second branch to GitHub. If the GitHub version is updated by others, I'd pull the changes into both of my branches. – user102162 Feb 07 '18 at 16:52
  • Worth thinking about: Git doesn't push *files* at all. During a Git-to-Git transaction (`git fetch` and `git push`), the sender sends *Git objects* (commits, trees, blobs, and annotated tags); the receiver stores the objects in the object database; then the sender offers the receiver some name/hash-ID pairings, which the receiver either takes, or doesn't, at its own discretion. Or, in short, `git push` pushes *commits* (plus whatever objects are needed to make the commits complete). Each commit is a stand-alone snapshot of every file. – torek Feb 07 '18 at 17:42
  • I'm not sure I see the relevance. Could you explain? – user102162 Feb 07 '18 at 17:50

1 Answers1

2

If it matters, the binary file contents won't change but more binary files will be added in the future, and it's possible that some binary files may be removed. I need the binary files to stay synced between my laptop and the server, and I want to keep backups in case anything is accidentally removed.

Then this is not (yet) a job for a Git repo: keep those binaries in a separate referential, automatically synchronized/saved (dropbox, google drive, OnePlus drive, Amazon S3, ...)

You can then keep only the sources in a Git repo, and, if you need, copy/rsync your binary from their backed-up folder to your local repo in order to have one tree structure with everything in it.
That same copy/rsync process can help detect any addition, modification, suppression of binaries in your local repo, mirror those in your backed up (dropbox, ...) binary folder, and keep those binaries in sync (and saved, but outside Git).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250