git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git-attic

From
PDPaul Gideon Dann <pdgiddie@googlemail.com>
Date
Jul 29, 2008, 11:57 UTC
Message-ID
<488F05B2.6060209@gmail.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
Next: Eric Raible
Message 1 of 2 in “git-attic”
  1. Paul Gideon DannJul 29, 2008
  2. Eric RaibleJul 29, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.