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
Then create a new tag. I use the format
$ git tag archive/branch-my-branch
Now we can upload the tags to Github or Gitlab
$ git push origin --tags
And delete the branch from local and origin repos.
Be sure to be in another branch like master
$ git checkout master
$ git branch -d my-branch $ git push origin :my-branch
If you need to delete the tag (an all the branch backup) from local
$ git tag -d archive/branch-my-branch
Or from origin
$ git push --delete origin archive/branch-my-branch
This will erase all tagged branch data though. Please be careful.