TWIL
git
Illustration of Emily presenting the Archive Branches Helper, a Git tool for archiving branches, depicting a tidy

Welcome to another installment of "TWIL," our weekly series where we share bite-sized insights into complex topics learned by our tech-savvy team. This week, Emily brings us a nifty Git tool for maintaining a tidy version control environment. Dive into her guide on creating an Archive Branches Helper, a shell command for efficiently archiving old Git branches, ensuring thorough housekeeping of your local and remote repositories without manual hassle. Keep your coding workspace clean and collaborate with ease, thanks to this clever shortcut.

Archive Branches Helper

Cleaning up old working branches is a great way to declutter both your local and remote repositories. But doing so can be tedious given all the steps required to maintain consistency between local and remote. Usually, you have to:

  1. tag the branch
  2. remove it locally
  3. remove it on remote
  4. push the tag to remote

So I wrote a shell command to do it for you! The archive-branch command is designed to archive a old git branches efficiently. This command ensures the branch is neatly archived and the repository remains organized.

# Archive a branch
# - Tag the branch as archived
# - Remove the branch locally
# - Remove the branch on origin
# - Push tag to remote
function archive-branch () {
  git tag archive/"$@" "$@" && git branch -D "$@"; git push origin :"$@"; git push origin archive/"$@"
}

In essence, a command like archive-branch contributes to a more manageable, understandable, and clean repository, which is fundamental for effective collaboration and project maintenance.

  • Git
Emily Morehouse's profile picture
Emily Morehouse

Cofounder, Director of Engineering

Related Posts

Illustration of Marisa demonstrating the process of Checking Out Pull Requests from Forked Remotes in Git, symbolizing the swift integration of important updates into a project's workflow.
July 17, 2019 • Frank Valcarcel

TWIL 2019-07-12

Dive into this week’s TWIL with Marisa to discover the a method to efficiently checkout and incorporate changes, even before they’re officially merged upstream.

Turtle swimming close to a life preserver as a metaphor for developers using Git version management to stay afloat
May 4, 2017 • Nick Farrell

Life-Saving Git Tips

From salvaging lost commits to streamlining your workflow, discover how to make your coding life smoother and avoid common pitfalls.