git symbolic-ref storage at central repo level

468 Views Asked by At

Idea is to have dev_release_branch all time acting just as alias to latest release branch of that environment ( dev in this eg ).

And to have new branch created post every release by some convention & to update symb ref every time post completion of migration or release to respective en.

git symbolic-ref -m "Updating rel branch ref to new" dev_rel_3rd_Nov dev_release_branch

Would like to store both reference & its mapped name in central repository. Is there a way to achieve this as simple git push HEAD:refs/for/dev_branch fails

This is to support incremental release process & hence computing files changed would be easier by comparison of 2 branch names hashes..

Thanks!

2

There are 2 best solutions below

0
On BEST ANSWER

Would like to store both reference & its mapped name in central repository. Is there a way to achieve this ...

Not from a client over the Git protocols.

Also, git symbolic-ref is a "plumbing" command (meant for scripts rather than casual use), and as a consequence, it requires that you spell out the full reference, e.g.:

git symbolic-ref refs/heads/foo refs/heads/master

Why the answer is "no"

Let's create a proper symbolic reference, and try pushing it:

$ git branch xyz master
$ git symbolic-ref refs/heads/foo refs/heads/xyz
$ git push origin foo
To [url]
 * [new branch]      foo -> xyz

Now, over on the server for origin:

$ git branch
* master
  xyz

This is, I think, what you observed that led you to say:

simple git push HEAD:refs/for/dev_branch fails

The problem here is that the push protocol literally has no way to push a symbolic reference. The protocol consists of a series of requests to set reference names to specific hash IDs. A symbolic reference is a reference that is set to a string that is not a hash ID.

This means that from a client, the only way to create a new symbolic reference on a server is to run Git commands directly on that server, e.g.:

ssh server "cd path/to/git/repo; git symbolic-ref ..."

The fetch protocol does allow retrieving symbolic references (in modern Git), but the push protocol does not allow setting them.

0
On

As torek answered, it is not possible.

But it sounds like a XY problem anyway, to me.

Your actual problem seems to be solvable: just have a tag dev_release_branch and update that after each release (using -f on the tag and push). Then it is up to creative use of git log, git show or some script grepping through .git/refs to find the corresponding individual branch name.