Archiving git branches

Camilo - Sep 25 '18 - - Dev Community

This is a quick way to archive a git branch. Maybe you do not use the code anymore and the branch is cluttering the repo but for backup or historical reasons you need to keep it somewhere.

The first thing is to checkout to the branch

$ git checkout my-branch
Enter fullscreen mode Exit fullscreen mode

Then create a new tag. I use the format archive/branch-{name}

$ git tag archive/branch-my-branch
Enter fullscreen mode Exit fullscreen mode

Now we can upload the tags to Github or Gitlab

$ git push origin --tags
Enter fullscreen mode Exit fullscreen mode

And delete the branch from local and origin repos.

Be sure to be in another branch like master

$ git checkout master
Enter fullscreen mode Exit fullscreen mode

Then

$ git branch -d my-branch
$ git push origin :my-branch
Enter fullscreen mode Exit fullscreen mode

If you need to delete the tag (an all the branch backup) from local

$ git tag -d archive/branch-my-branch
Enter fullscreen mode Exit fullscreen mode

Or from origin

$ git push --delete origin archive/branch-my-branch
Enter fullscreen mode Exit fullscreen mode

This will erase all tagged branch data though. Please be careful.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player