1

Enough of a newbie that I can't fully understand the answers enter link description here and enter link description here.

The master is on my computer and I have about 50 branches. I'm also pushing it to Bitbucket and heroku for serving.

I'd like to 1) delete all the old branches, but I wouldn't mind 2) having a copy of the log just in case I want to go back and look at something. Can this be done?

I'm using TextMate and use it for many of the Git tasks; and also have SourceTree, but haven't really used it.

Community
  • 1
  • 1
Greg
  • 1,867
  • 2
  • 16
  • 25
  • You want the branches for an archive, but you want to delete all the old branches. How do you expect us to reconcile this contradiction? – Alexander Mar 02 '17 at 20:08
  • The archive is an option. It might look like diff. Some kind of searchable text file. – Greg Mar 02 '17 at 20:10
  • well you'll have to create that yourself. Branches are markers of concurrent, undergoing work, they're not meant to be archived, they're meant to be merged. – Alexander Mar 02 '17 at 20:18
  • I just created a disk image as a not too easy to mess up backup. – Greg Mar 02 '17 at 20:31

1 Answers1

1

1) delete all the old branches, but I wouldn't mind 2) having a copy of the log just in case I want to go back and look at something. Can this be done?

If those branches are following a pattern in their naming convention, you can, in a git bash shell session, do a:

git branch -D $(git for-each-ref --format="%(refname:short)" refs/heads/<pattern>)

git reflog will provide you a way to get back and restore any branch locally... at least for the next 30 days. At which point, said reflog would be expired and pruned.

But you could also make a git clone --mirror of your repo before trying to delete everything, that way, you would still have a local copy.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • No consistent naming convention. If I create a clone, will I have to start over with Heroku? That would be inconvenient since the URL would change. Thank you for answering. – Greg Mar 02 '17 at 20:07
  • @Greg creating a clone is just for safekeeping. As for the deletion , you can simply list those branches in the `git branch -D` command, separated by a space. – VonC Mar 02 '17 at 20:10
  • Got it. But not quite sure of the syntax `git branch -D branch-1, branch-2` or ? – Greg Mar 02 '17 at 20:13
  • @Greg "space-separated" means no comma involved: `git branch -D b1 b2 b3` – VonC Mar 02 '17 at 20:16