Read Anthropic’s case study about Graphite Reviewer

How to implement feature branch workflows in GitHub

Sara Verdi
Sara Verdi
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Feature branch workflows are a key part of modern development practices, especially when multiple developers are working on the same project but on different features or fixes. By implementing a feature branch workflow in GitHub, teams can isolate development work, reduce conflicts, and increase the quality of the main development line. Here’s a guide to setting up and optimizing feature branch workflows in GitHub, including how Graphite can enhance this process with its stacking capabilities.

A feature branch workflow involves creating a separate branch in a Git repository for each new feature, bug fix, or experiment. This keeps the main branch clean and stable, as all the development work is done on these isolated branches. Once a feature is complete, the branch is merged back into the main branch.

Here’s how you can set up feature branches in GitHub:

  1. Create a new branch for each feature: Use the GitHub interface or the command line to create a new branch from the main branch whenever you start working on a new feature. The branch name should be descriptive, like feature/user-authentication or fix/header-bug.

    Terminal
    git checkout main
    git pull origin main
    git checkout -b feature/user-authentication
  2. Commit your changes regularly: Make small, incremental commits that clearly describe the changes. This not only helps in tracking changes but also makes it easier to integrate changes back into the main branch.

    Terminal
    git add .
    git commit -m "Add user authentication form"
    git push origin feature/user-authentication
  3. Keep your feature branch updated: Regularly sync your feature branch with the main branch to avoid merge conflicts. You can do this by merging or rebasing the main branch into your feature branch.

    Terminal
    git checkout feature/user-authentication
    git pull origin main
    git merge main
  4. Open a pull request: Once your feature is ready, open a pull request (PR) in GitHub from your feature branch to the main branch. This allows your team to review the changes before they are merged into the main.

  5. Review and merge the pull request: After the team reviews and approves the PR, you can merge it into the main branch. Ensure that your CI/CD pipeline runs tests and checks to validate the feature before it is merged.

Graphite enhances the feature branch workflow by allowing developers to stack changes on top of each other. This is especially useful in environments where features are dependent on each other or need to be developed in a sequence.

  1. Create stacked branches with Graphite: Graphite's tooling lets you create branches that are logically stacked on top of each other, making it easier to manage dependencies between features.

    Terminal
    gt branch create feature/user-authentication
    gt branch create feature/user-profile --parent feature/user-authentication
  2. Manage your stacks: Graphite provides a visual interface and command-line tools to manage your branch stacks, ensuring that changes flow correctly between dependent branches.

screenshot of a stack in the CLI

  1. Automate stacking via pull requests: When you open a PR with Graphite, it can automatically adjust the base of stacked pull requests as each layer of the stack is merged, simplifying the integration process and reducing merge conflicts.

By implementing feature branch workflows and integrating Graphite's stacking capabilities, teams can maintain cleaner code bases, reduce integration headaches, and streamline the development process. Remember to follow feature branch best practices and regularly review your workflow to adjust to changing project needs.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Built for the world's fastest engineering teams, now available for everyone