4

Is it ok to rename branches in bare repository at packed-refs file?

I want to rename it from:

# pack-refs with: peeled fully-peeled 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa refs/heads/master
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb refs/heads/new

to:

# pack-refs with: peeled fully-peeled 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa refs/heads/old
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb refs/heads/master
Dmitriy Kozmenko
  • 1,027
  • 7
  • 14
  • 4
    It looks like you're not asking about renaming a *repository*, but rather about renaming branches *within* a repository. If so, note that `git branch -m` works on bare repositories as well as non-bare ones. – torek Jul 12 '15 at 22:17
  • yes, i'm sorry... my question was wrong. you are right of course i want to rename branches in repository. I'll check git branch -m, but I renamed already in packed-refs, so I still have my question - can I do it? or not :( – Dmitriy Kozmenko Jul 13 '15 at 02:59
  • 1
    Writing directly to packed-refs *works* (at least, it works *now* under the condition that the same ref does not exist as an unpacked one). You can check by running `git branch` on the server, or by using `git ls-remote` on a client. In general, though, you should just use normal git commands; that way what you're doing will still work in future versions of git. – torek Jul 13 '15 at 05:16
  • Thank you torek, `git branch -m` really work :) Can you add `git branch -m` as answer on this question? This is correct answer.... – Dmitriy Kozmenko Jul 13 '15 at 12:56

1 Answers1

3

As torek stated:

You can rename branches by issuing the command

Usage:

git branch -m <oldbranch> <newbranch>

Source: https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

madonius
  • 451
  • 4
  • 6
  • This seems to ignore the (pretty clearly emphasized) "bare" part of the question. I mean how is this command issued for a bare repo that _doesn't_ (normally) have a workspace? (The linked page also mentions "bare" 0 times.) But if Dmitriy was OK with it... (which is puzzling...), who am I to object? :) – Sz. Mar 01 '23 at 14:08