belltown
belltown

Reputation: 41

How do I create a Git remote repository that omits certain files from the original repository?

I have project files (including test files) all of which I want under version control using Git on my local computer. I want to create a public remote repository (on GitHub) that only contains a subset of my project files (I want some of the test files in my project to be omitted from the public remote repository.)

How do I set up the remote repository so that certain files are omitted and that there is no reference in the remote repository or its history that these files ever existed?

Upvotes: 2

Views: 376

Answers (1)

larsks
larsks

Reputation: 312253

Try this:

  • Initialize your git repository:

    git init
    
  • Add all your public files and make your initial commit:

    git add public1 public2 ...
    git commit -m 'initial commit'
    
  • Create a new private branch:

    git checkout -b private
    
  • Add your test files and other things you don't want publically exposed:

    git add testcase1 testcase2 ...
    git commit -m 'added test cases'
    

Now you have a repository with two branches. The master branch contains only those things you want to publically expose. The private branch is based on the master branch, but has some additional files.

Add your github remote and push the master branch.

You'll want to do most of your work on the master branch, periodically merging changes into the private branch as necessary.

UPDATE: If you need to work on the files frequently, this becomes complicated because it will be hard to separate changes from your "private" files from changes to your public files. If all your private files can be confined to a specific subdirectory, the easiest thing to do is just to put your private files in a separate repository (and have the working copy checked out inside the public repository).

Even if you can't confine everything to the same subdirectory, you can pursue a similar solution through creative use of symlinks.

Upvotes: 1

Related Questions