Skip to content

Instantly share code, notes, and snippets.

@jackdempsey
Created July 16, 2010 21:52
Show Gist options
  • Save jackdempsey/478969 to your computer and use it in GitHub Desktop.
Save jackdempsey/478969 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
die()
{
echo "fatal: $@" >&2
exit 1
}
test $# -eq 1 || die "invalid number of arguments"
src=refs/heads/$1
old=$(git show-ref --hash --verify "$src" 2>/dev/null) ||
die "not a valid branch: $1"
dst=refs/hidden/$1
! git rev-parse -q --verify "$dst" >/dev/null ||
die "ref already exists: $dst"
git update-ref "$dst" "$src"
# cleanup
git update-ref -d "$src" "$old" ||
git update-ref -d "$dst" "$old" 2>/dev/null
#!/bin/sh
set -e
die()
{
echo "fatal: $@" >&2
exit 1
}
listhidden()
{
echo "Hidden branches:"
ls .git/refs/hidden
exit
}
test $# -eq 1 || listhidden
src=refs/hidden/$1
old=$(git show-ref --hash --verify "$src" 2>/dev/null) || die "not a valid branch: $1"
dst=refs/heads/$1
! git rev-parse -q --verify "$dst" >/dev/null || die "ref already exists: $dst"
git update-ref "$dst" "$src"
# cleanup
git update-ref -d "$src" "$old" || git update-ref -d "$dst" "$old" 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment