Skip to content

Instantly share code, notes, and snippets.

@kattatzu
Last active January 8, 2020 23:20
Show Gist options
  • Save kattatzu/a3ab4b00aa77a455109496d8a7a1b12e to your computer and use it in GitHub Desktop.
Save kattatzu/a3ab4b00aa77a455109496d8a7a1b12e to your computer and use it in GitHub Desktop.

For archive the branches that are no longer used I created a function in my .zshrc file (or .bashrc). The content of the branch is saved in a new tag and subsequently deleted.

To make this process faster I created this function in my .zshrc file (or .bashrc).

function archive_branch() {
  date=$(date '+%Y-%m-%d')

  git checkout master
  git tag archive/$date-$1 $1
  git branch -D $1
  git branch -d -r origin/$1
  git push --tags
  git push origin :$1
}

In console runs like this:

archive_branch fix-bug-123

This will remove the branch you want to archive and create a tag with its content in the following format:

archive/2020-01-08-fix-bug-123

regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment