Perhaps the no.1 barrier to open-sourcing useful code and sharing it with the community is the fact that it’s often written in a larger, private project.

Open-sourcing parts of your project would usually mean having to split and refactor your project just to put parts of it as new projects on GitHub.

This overhead is usually enough to block most of us from sharing useful pieces of code we write every day, which could make excellent open source modules.

Those who do, like Sindre Sorhus, make a huge impact on the community by saving people the need to re-invent the smaller building blocks for every project they build. Imagine a world where everyone could be Sindre.

Sindre’s 1000th NPM package

Lowering the overhead barriers to sharing parts of private projects can help the community share more code, and leverage each other’s work to build new things faster instead of re-inventing the pieces they’re built from.

In this short post I’ll show how using (open source project) Bit you can quickly open-source parts of your existing private GitHub, GitLab or BitBucket projects without having to split the project or compromise its privacy.

How is that possible?

The things about Bit is that it was built to allow the isolation and sharing of small components. These can be common functionalities, small modules or even UI components, all of which are basically just sets of files in your repo.

Using Bit, you can isolate these sets of files (we call code components) from your project and share them with the open source community, while keeping their source project private and intact.

Let’s look at this example project structure which includes a component called hello-world . Let’s say that this project is private, but we think that hello-world would make a great module for the open-source community.

.

├── bit.json

├── package.json

└── src

├── hello-world

│ ├── hello-world.js

│ └── index.js

└── utils

└── noop.js

Before Bit, we would have to create a new GitHub project for this component, remove hello-world from your private project and make all its dependancies (packages as well as other files from the project) available for the new project.

With Bit, you can keep this component as part of your private project and still make it available to the community to discover, use and collaborate on.

This becomes possible thanks to Bit’s ability to isolate sets of files from the project as components. When you use the bit add command to point Bit to sets of files in your repository it will start tracking them as components.

Bit will also read through the files and looks for import or require statements to find dependencies for the code. If it finds any, it will figure out if they are either package dependencies or additional files from the project.

When you use the bit tag command Bit locks the components’ dependency graphs in place, and also locks a version for the components it tracks.

Open source parts of your project to the community

To make sure your components are truly executable outside of the project’s context, Bit will build an isolated component environment and apply all configured extensions to test, compile or perform any other defined task.

By now, your private project remained in tact while Bit identified, isolated and prepared the part of it you want to share with the open source community.

Share with the community

You can share component to Bit’s free hub, to your own servers and also to GitHub, it’s really your choice.

The simplest way would be to share your components to the free Bit Hub. From there they will be made available to the world to discover and use with NPM, Yarn or even Bit itself (to develop them from other projects).

Here is an example React application on GitHub. It’s open source, but could have just as easily been a private repository from an organization.

Using Bit, all its React UI components were shared to the Hub and organized in a Bit Scope. Here is what a UI component looks like after shared with Bit.