How to delete all old merged Git branches

Greg Foster
Greg Foster
Graphite software engineer

A common post-merge task in the development workflow is cleaning up the branches that have already been incorporated into the main branch. This housekeeping is essential for maintaining an organized and efficient repository. Graphite CLI introduces a straightforward way to handle this cleanup with the gt sync command.

Callout: Remember, gt sync is more than just a clean-up command; it’s a harmonizing tool that aligns your local workspace with the remote repository.

  • Automated Housekeeping: The gt sync command streamlines the clean-up process by automatically removing local branches that have been merged remotely.

  • Syncing with Remote: It ensures your local branches are up-to-date with the remote branches, reducing the chance of merge conflicts and confusion over branch status.

  1. Update Your Local Repository: Before cleaning up, ensure your local repository is in sync with the remote.

    gt repo sync

  2. Run the Sync Command: Use gt sync to clean up your branches. This command will sync your current branch with the remote, prune remote-tracking branches, and delete branches that have been merged into the current branch.

    gt sync

    By default, gt sync will clean up branches that have been merged into the branch that you're currently on.

Callout: After running gt sync, your local branch list will be pruned, reflecting only the active branches that are still in development or review.

Integrate the gt sync command into your daily workflow to ensure your repository remains clean and manageable. Running it after a series of merges or at the end of a workday can keep your workspace tidy and up-to-date.

The gt sync command from Graphite is a powerful tool that not only updates your branches but also assists in maintaining a neat repository by removing branches that have served their purpose. Adopting this command into your regular workflow can save time and avoid the confusion that comes with a cluttered branch list.

For further details on gt sync and other Graphite commands, visit the Graphite documentation. Here you'll find a wealth of information to help you maximize your efficiency with Graphite's suite of tools.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Get started

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2