Skip to Main Content
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

Digital pioneer journeying through technological quirks, reminiscent of vast waterfalls and rocky terrains
April 5, 2017 • Kyle Misencik

Infinitely dispatching actions + React, Redux & React Router v4

While implementing JWT for an application, we ran into a quirk with React Router v4. Here, we hope to show how to implement protected client-side routes while avoiding some of the pitfalls we encountered.

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.