# git-attic

2 messages from 2008-07-29 to 2008-07-29. Participants: Paul Gideon Dann, Eric Raible.
Thread: https://gitlist.dev/t/14736

## Paul Gideon Dann, 2008-07-29 11:57

Subject: git-attic
Message-ID: <488F05B2.6060209@gmail.com>
URL: https://gitlist.dev/e/488F05B2.6060209%40gmail.com

```
Hello all,

I looked around everywhere for a script that could make it easy for me 
to store stale branches in refs/attic for possible later retrieval.  I 
don't like such branches lying around in refs/heads and used to tag them 
to clear them out of the way, but then that makes "git push origin 
--tags" unusable, since I don't want to push my stale branches out...

Anyway, I wrote my own little script in the end and thought it might be 
useful to others.

Please Cc pdgiddie@gmail.com in replies,
Paul Gideon Dann


Usage: git-attic
       git-attic store <ref> [<commit>]
       git-attic remove <ref>


#!/bin/bash
###
# Original Author: Paul Gideon Dann <pdgiddie@gmail.com>
###

showUsage() {
  echo "Usage: git-attic"
  echo "       git-attic store <ref> [<commit>]"
  echo "       git-attic remove <ref>"
}

case $1 in
  "store")
    if [[ ! $2 ]]; then
      showUsage
      exit 1
    fi
    if [[ $3 ]]; then
      OBJECT_SHA1=`git-rev-parse --revs-only $3`
      if [[ ! $OBJECT_SHA1 ]]; then
        echo "$3 is not a recognisable commit object."
        exit 1
      fi
    else
      OBJECT_SHA1=`git show-ref -h HEAD | awk '{print $1}'`
    fi
    git update-ref refs/attic/$2 $OBJECT_SHA1
    echo "$2 stored in attic."
    ;;

  "remove")
    if [[ ! $2 ]]; then
      showUsage
      exit 1
    fi
    OBJECT_SHA1=`git show-ref attic/$2 | awk '{print $1}'`
    if [[ ! $OBJECT_SHA1 ]]; then
      echo "$2 does not exist in the attic!"
      exit 1
    fi
    git update-ref -d refs/attic/$2 $OBJECT_SHA1
    echo "$2 removed from attic."
    ;;

  *)
    if [[ $1 ]]; then
      showUsage
    else
      # display contents of attic
      git for-each-ref --format="%(refname)" refs/attic | awk -F / 
'{print $3}'
    fi
    ;;
esac

```

## Eric Raible, 2008-07-29 16:51

Subject: Re: git-attic
Message-ID: <loom.20080729T164914-281@post.gmane.org>
URL: https://gitlist.dev/e/loom.20080729T164914-281%40post.gmane.org
In-Reply-To: <488F05B2.6060209@gmail.com>

```
Paul Gideon Dann <pdgiddie <at> googlemail.com> writes:

>       OBJECT_SHA1=`git show-ref -h HEAD | awk '{print $1}'`

OBJECT_SHA1=`git show-ref --hash --head HEAD`

```
