Quick Start

Using Bit - What to do?

Follow these steps to learn the basics that you need to start working with Bit. We’ll start by choosing a project and components to share from it, all the way to importing and using them in any other project with your favorite tools.
When finished, you will also have a beautiful gallery of components ready to share with your team.

Install bit

npm install bit-bin -g

See additional installation methods.

Choose components to share

Choose a component from your own project, or use one of the examples available here.

Init Bit for your project

Run this command to initialize a Bit workspace.

$ cd project-directory
$ bit init

Track files (components) with Bit

Bit isolates and tracks files in your repository and set them as components.
To track components use bit add.

bit add src/components/* # use a glob pattern or a specific path to track multiple components or a single component.

Bit automatically scans the files it tracks for their dependencies (packages and files), to resolve out their dependency graph.

Tip

Use the bit status command to verify that each component’s dependency graph was successfully built and resolved.

Example

Let’s track the components button, login and logo in the following project’s directory structure.

$ tree
.
├── App.js
├── App.test.js
├── favicon.ico
├── index.js
└── src
    └── components
        ├── button
        │   ├── Button.js
        │   ├── Button.spec.js
        │   └── index.js
        ├── login
        │   ├── Login.js
        │   ├── Login.spec.js
        │   └── index.js
        └── logo
            ├── Logo.js
            ├── Logo.spec.js
            └── index.js

5 directories, 13 files

To track these files as components we can use the bit add with a glob pattern.

$ bit add src/components/*
tracking 3 new components

Add build and test tasks

Bit supports managing build and test tasks for each component. You can add a Bit build/test task to your project, and they will be set and run for each tracked component.

Read more about adding build environment and test environment to your project.

Here is a list of curated build and test environments, for you to get started quickly.

You can specify the component’s test files with the bit add command and --test flag, to let Bit know these are test files and should be part of your component.

Version components

Setting a version for a component locks the state of the component’s files and the dependency graph, and sets a semantic version to the component, thus making each component-version immutable. When tagging a component, all its build and test tasks will run, and only if all is working correctly, Bit will version the component.

$ bit tag --all 1.0.0
3 components tagged | 3 added, 0 changed, 0 auto-tagged
added components:  components/button@1.0.0, components/login@1.0.0, components/logo@1.0.0

Export versioned components

Create a Scope

In order to export a component, you need to create a free account in bitsrc.io, and then create a Scope. A Scope is a remote Bit directory, similar to a git repository, that can host and manage components.

There is more to learn about managing components in Scopes. You can check out some example Scopes we created for React components.

Export components

Unlike publishing packages, exporting a component will not change the project’s source code or force you to set up any additional repositories.

$ bit export username.scopename  # Share components to this Scope
exported 3 components to scope username.scopename

Use components in other projects

Install with NPM / Yarn

Components shared to Bit can automatically be installed with the NPM / Yarn client or with any package manager that implements the CommonJS package registry specification.

You can now install the components you just exported with NPM / Yarn. This allows projects and developers which are not familiar with Bit, to still use your Bit components.

It is also possible to source the components directly to another project, using Bit. If you choose to source your components, you can also modify them later from the consumer project, and export the modifications back to bitsrc.io as a new version for that component.

Example Projects

Want more examples? We’ve created a few example projects that will help you learn how to use bit (don’t forget to take a look at each project’s readme file on GitHub):

Summary

You are now ready to work with Bit and easily share code between your projects.
Feel free to learn more through the different sections of the docs, search the Bit website for components or visit Bit on GitHub.