Trunk Base Development with Feature flag
Published: 2023-04-24 02:50:23

There are many things that happen while developing an application. But when you’re building an application with a big team, a common question that arises is how to use Git effectively.

> Git architecture is crucial in managing any project, as it helps you maintain your application code as well as its stability. Many times, if the Git architecture of an application is not good, you may feel frustrated because every commit or push creates conflicts, which can later lead to code instability.

Hence, there are several ways, but here I am discussing one of the most effective ways, which is trunk-based development.

![Old Process](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yy0etiphu9dbiuj144rj.png)



A new modern way Trunk base

Trunk-based development is a software development approach in which all developers work on a single shared codebase, often referred to as the “trunk”. It involves developers frequently committing code changes to the mainline of the codebase, which is then built and tested on a continuous basis to ensure that the software remains functional and stable.

This approach encourages collaboration and minimizes the risk of conflicts or delays that may arise when working with feature branches. Trunk-based development is commonly used in Agile software development methodologies and is well-suited for teams that prioritise rapid and continuous software delivery.


![Trunk base development](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hy0p7yjl95ixi1qmd74n.png)


Here are the steps to create a new Git feature branch:

1. Start by switching to the main branch of your Git repository. You can do this by running the command:

`git checkout main`
2. Once you are on the main branch, pull the latest changes from the remote repository to ensure that you are working with the most up-to-date code. You can do this by running the command:

`git pull`
3. Create a new feature branch by running the command:

`git checkout -b <feature-branch-name>`
Replace `<feature-branch-name>` with a descriptive name for your new branch.

4. Start making changes to your code on the new feature branch. You can use the `git status` command to view the current status of your branch and the `git add` command to stage changes for commit.

5. Once you have made your changes and are ready to commit them, use the `git commit` command to commit your changes to the feature branch. Be sure to include a descriptive commit message that explains the changes you have made.

6. Continue working on your feature branch, committing changes as necessary, until the feature is complete.

7. Push your changes to the remote repository:

`git push`
These are the general steps to create and merge a new Git feature branch. The specific commands and workflow may vary depending on your specific Git repository and development environment.

> Feature flags allow you to toggle specific features on or off in your codebase without having to create separate branches. Feature branches, on the other hand, allow you to create a separate branch in your repository to work on a specific feature.

There are several websites and services available that allow you to generate feature flags for your projects. Here are a few examples:

1. LaunchDarkly (https://launchdarkly.com/): LaunchDarkly is a feature management platform that allows you to manage feature flags for your applications. It provides a web-based dashboard where you can create and manage flags, and also offers SDKs for various programming languages.

2. Split (https://www.split.io/): Split is another feature flag management platform that allows you to manage feature flags for your applications. It provides a web-based dashboard, SDKs for various programming languages, and also integrates with popular development tools like Jira and GitHub.

3. Unleash (https://unleash.github.io/): Unleash is an open-source feature flag management system that allows you to manage feature flags for your applications. It provides a simple API and a web-based dashboard, and also offers SDKs for various programming languages.

4. Flagsmith (https://flagsmith.com/): Flagsmith is a cloud-based feature flag management platform that allows you to manage feature flags for your applications. It provides a web-based dashboard, SDKs for various programming languages, and also integrates with popular development tools like GitHub and Bitbucket.

These are just a few examples of the many feature flag management tools available. It’s important to evaluate each tool based on your specific needs and requirements before choosing one for your project.

Once the changes done create the pull request.

Bonus Git Advance Commands

1. `git rebase`: This command is used to change the base branch of your current branch. It essentially takes the changes from your current branch and applies them on top of the latest changes in the new base branch, resulting in a cleaner commit history.

2. `git cherry-pick`: This command is used to apply a specific commit from one branch to another. This can be useful when you need to apply a bug fix or a specific feature to another branch without merging the entire branch.

3. `git reflog`: This command is used to view the history of all the Git commands that have been executed on your repository, even if they were undone or lost due to a rebase or reset.

4. `git bisect`: This command is used for binary search debugging. It helps you find the specific commit where a bug was introduced by recursively checking out and testing different commits until the faulty commit is found.

5. `git stash`: This command is used to temporarily save changes that are not yet ready to be committed. This can be useful when you need to switch to another branch or pull in changes from another branch without committing your changes.

6. `git submodule`: This command is used to manage external dependencies in your Git repository. It allows you to include a separate Git repository within your main repository as a subdirectory.

7. `git filter-branch`: This command is used to rewrite the Git history by modifying the commit messages, author names, or files in your repository. This can be useful when you need to clean up a repository’s history or remove sensitive information.

Ref: [Blog](https://theplainscript.medium.com/trunk-base-development-with-feature-flag-89cf1df7fa5d)