Git + Bit: Code Meets Components

Keeping Git Branches and Bit Lanes in Sync for Seamless DevelopmentAs codebases evolve, they often grow in complexity. They also become heterogeneous, storing application code, infrastructure configurations, libraries, cloud functions, and more.This is…


This content originally appeared on Bits and Pieces - Medium and was authored by Ashan Fernando

Keeping Git Branches and Bit Lanes in Sync for Seamless Development

As codebases evolve, they often grow in complexity. They also become heterogeneous, storing application code, infrastructure configurations, libraries, cloud functions, and more.

This is where the Bit steps in. You can divide your codebase into a collection of fundamental units called Bit Components.

Bit Components

These components can encapsulate various types of code, including UI components, utility libraries, cloud functions, infrastructure configuration, backend logic, and more. These components can be composed together to build different functionality. Each component has its own lifecycle and version control outside the Git repository in a remote Bit Platform.

Bit Platform provides the capability to store components more like having a Git repository for each component

Whether you’re using a monorepo approach or dividing your projects into multiple Git repositories, these components can be consumed by any part of code, pulling them down from the Bit platform.

Code Meets Components

Git Repo and Bit Components

Once you build your codebase as a collection of components, you may need to ensure that your component versions in the Bit platform and your Git repositories are in Sync.

You also need to consider your Git branching strategy and Bit lane strategy before implementing the approach to keep components and codebases up to date.

New to Bit Lanes?

If you are new to Bit lanes, it’s worth understanding its characteristics as there are several differences between the Git branches. In the Bit ecosystem, the lane “main” keeps track of all the up-to-date component versions that have been explicitly tagged. If you need to modify several components, you can create a different lane.

The main difference of Bit lanes (except “main” lane) with Git branches is that, the lanes will only keep track of the modified components.

However, these differences look minor when synchronizing components with code could become complicated if you try to do it from scratch. Knowing this, the Bit team has already provided the necessary support for popular Git platforms to make this happen.

Bit Integrations with Git Platforms

Bit and Git Integration Scripts

Currently Bit provide direct integrations for a range of popular Git Platforms with examples. You can find the list of supported platforms as follows.

  • GitHub
  • GitLab
  • BitBucket
  • AzureDevOps
  • Jenkins

And, if you need to support any other platforms, Bit provides a docker container, shell scripts, and node scripts that you can use as the building blocks to implement your own custom integration.

If you look into the scripts for each platform integration, you can find multiple scripts or tasks.

We can categorize them into three main workflows that help synchronize code and components.

Synchronize Code Changes from Git Repository into Bit Platform

If you are following feature branch workflow with Git and want to test components before you merge a Pull Request, you need to implement this workflow. This includes the use of the following scripts.

  1. Bit Initialize — Pre-requisite before running any other script since this installs Bit CLI and run bit install command in your workspace.
  2. Bit Pull Request Build — This script needs to be triggered when creating a Pull Request. It will export all the component changes to a Bit lane so that you can test your components in Bit Platform. You can also find examples for each CI platform's Bit Tasks repository.
  3. Bit Tag and Export and Commit Bitmap — These two tasks work together. Once you merge a Pull Request with component changes, this will synchronize component changes with the Bit Platform (Tag and Export). Then, the updated versions will be committed back to the Git repository.

By following this workflow, you can continue working with your Git repository, and the CI setup will ensure that the component changes are synchronized into the Bit Platform.

In addition to this, you can use Branch Lane script, to create a Bit Lane in Bit Platform correspending to a specific Branch in Git. It is useful if you need to do any manual verifications or integration tests in Bit Platform.

Synchronize Component Changes from Bit Platform into Git Repository

This workflow is unique and specifically useful if you develop components using Bit Cloud Workspaces or from a newly created Local Workspace (not tracked in Git).

In this workflow, you may create a Bit lane and modify components. If you want to synchronize modified components with your Git repository, use the Bit Lane Branch script.

This script uses a lane name as the input and copies all the modified components from a Bit lane into a new branch in the Git repository. Since the Bit lane contains only the modified components, the script first imports the changes into the “main” branch and then creates a new branch including these modified components.

Finally, it commits these changes and pushes them into the Git repository. Following is the Branch Lane shell script that showcases each command.

#!/bin/bash

# When using this script, ensure that you remove "bit install" command from the bit-init script, if you us it prior to running this one.

# Arguments to the script
WSDIR="$1"
LANE_NAME="$2"
BRANCH_NAME="$3"

# Change to working directory before running the commands
cd "${WSDIR}"

# Run the commands

bit import -x
bit lane import "${LANE_NAME}"
bit init --reset-lane-new

# Set git configuration
git config --global user.name "${GIT_USER_NAME}"
git config --global user.email "${GIT_USER_EMAIL}"

# Git operations
git checkout -b "${BRANCH_NAME}"
git add .
git commit -m "Committing the latest updates from lane: ${LANE_NAME} to the Git branch (automated) [skip-ci]" 2> /dev/null
if [ $? -ne 0 ]; then
echo "Error while committing changes"
fi

git push origin "${BRANCH_NAME}" -f

You can find the implementation of this script for each of the following platforms.

Once the branch is created with the modified components, you can create a Pull Request for your “main” branch or merge it directly.

Conclusion

Using the Bit platform, you can modularize your code into components that are versioned and managed independently of your Git repository.

The integration between Bit and Git ensures that these components remain in sync, whether you’re pushing code changes from Git to Bit or pulling component updates from Bit into Git. The workflows and scripts provided by Bit, such as the Branch Lane script, make this process efficient, enabling you to keep your codebase and components aligned across both platforms.

As you implement these strategies, you can confidently manage the growing complexity of your projects while ensuring that your development workflow remains smooth and error-free.

I hope you found this article helpful in understanding different strategies to keep Git and Bit in sync for seamless development. If you have any thoughts, questions, or experiences, please feel free to comment below — I’d love to hear from you!

Learn More


Git + Bit: Code Meets Components was originally published in Bits and Pieces on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Bits and Pieces - Medium and was authored by Ashan Fernando


Print Share Comment Cite Upload Translate Updates
APA

Ashan Fernando | Sciencx (2024-08-29T10:22:51+00:00) Git + Bit: Code Meets Components. Retrieved from https://www.scien.cx/2024/08/29/git-bit-code-meets-components/

MLA
" » Git + Bit: Code Meets Components." Ashan Fernando | Sciencx - Thursday August 29, 2024, https://www.scien.cx/2024/08/29/git-bit-code-meets-components/
HARVARD
Ashan Fernando | Sciencx Thursday August 29, 2024 » Git + Bit: Code Meets Components., viewed ,<https://www.scien.cx/2024/08/29/git-bit-code-meets-components/>
VANCOUVER
Ashan Fernando | Sciencx - » Git + Bit: Code Meets Components. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/29/git-bit-code-meets-components/
CHICAGO
" » Git + Bit: Code Meets Components." Ashan Fernando | Sciencx - Accessed . https://www.scien.cx/2024/08/29/git-bit-code-meets-components/
IEEE
" » Git + Bit: Code Meets Components." Ashan Fernando | Sciencx [Online]. Available: https://www.scien.cx/2024/08/29/git-bit-code-meets-components/. [Accessed: ]
rf:citation
» Git + Bit: Code Meets Components | Ashan Fernando | Sciencx | https://www.scien.cx/2024/08/29/git-bit-code-meets-components/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.