Executing Fast-Forward Merges
What
Executing a fast-forward merge and cleaning up your local environment by deleting obsolete branches is a standard daily housekeeping workflow for all software developers.
How
The complete workflow cycle of creating a feature, fast-forward merging it, and cleaning up involves:
-
Isolate: Create a new branch and commit your changes:
git switch -c update_titles # (Modify files, stage changes) git commit -m "Update titles lists" -
Merge: Switch back to the base branch and merge:
git switch main git merge update_titles # Output: Updating B..C \n Fast-forward -
Cleanup: Delete the now obsolete local feature branch pointer:
git branch -d update_titles
Note: The -d flag stands for delete. Git will check to ensure the branch’s commits have been successfully merged into your active branch before deleting it, acting as a safeguard against accidental code loss.
Why
Once a branch’s changes have been fast-forwarded into main, the branch pointer serves no further purpose. Deleting the branch pointer (git branch -d) does not delete the underlying commits; it simply removes the lightweight reference name from your local terminal output. This keeps your list of branches small, neat, and organized.
Summary
Combine git merge with git branch -d <branch_name> to cleanly fast-forward your features and prune merged branch pointers from your workspace.