Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chopfitzroy/8939f9a21e0fa48c8ea63d566ccf3d80 to your computer and use it in GitHub Desktop.
Save chopfitzroy/8939f9a21e0fa48c8ea63d566ccf3d80 to your computer and use it in GitHub Desktop.
Procedure to archive git branches.

How to prune unwanted git branches

Discover unwanted branchs

From http://www.darkcoding.net/software/cleaning-up-old-git-branches/

  1. Switch to the main branch, usually 'develop':

     git checkout develop
    
  2. Get a list of fully merged branches:

     git branch -a --merged
    

Prune unwanted branches

From http://www.aaronwest.net/blog/index.cfm/2011/6/7/Git-Workflows-Archiving-Old-Branches

  1. Tag the unwanted branch:

     git tag archive/sprintjuly2010 sprintjuly2010
    
  2. Delete the branch:

     git branch -d sprintjuly2010
    
  3. Push the branch deletion to origin:

     git push origin :sprintjuly2010
    
  4. Push the new tag to origin:

     git push --tags
    
  5. Restore a deleted branch from a tag:

     git checkout -b sprintjuly2010 archive/sprintjuly2010
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment