-1

I have several sensitive images on a computer vision program I created that I don't want public but I want to share the main python code. Is there a way to make only certain files in a github repository public while keeping other files private?

Alvino123
  • 21
  • 4

2 Answers2

1

Add sensitive files to your .gitignore file, which will prevent them from being picked up by Git:

# Add a specific file:
path/to/sensitive/file.txt
# Add an entire folder
a/whole/folder
# Add all files of type "txt"
*.txt

You can find documentation for .gitignore here: https://git-scm.com/docs/gitignore

Note that this will not make git "forget" already tracked files, to untrack files without deleting them from your computer, you'll have to git rm --cached file_to_untrack.txt. Omit --cached to delete from your computer as well.

  • 2
    Note: it's called "gitignore", not "gitforget", because it won't ignore files you've already added. If you've already added those files then you'll need to follow the link in evolutionxbox's comment to remove them. – Jim Redmond Jul 27 '23 at 20:24
  • 2
    Good point! I've updated my answer to reflect this – InsertDisplayNameHere Jul 27 '23 at 20:26
1

You could use git-crypt for this:

git-crypt lets you freely share a repository containing a mix of public and private content. git-crypt gracefully degrades, so developers without the secret key can still clone and commit to a repository with encrypted files. This lets you store your secret material (such as keys or passwords) in the same repository as your code, without requiring you to lock down your entire repository.

https://github.com/AGWA/git-crypt

This lets you check the files in and share them (or not) with collaborators.

chelmertz
  • 20,399
  • 5
  • 40
  • 46