R.. R.. - 1 month ago 31
Git Question

GIT Symbolic Reference (Alias) on remote Repository branch?

Is there any way to push an alias created locally to a remote repository?

I have checked out the remote branch v1.0.

I have created the alias (green_horn) to the local copy like this:

git symbolic-ref refs/heads/green_horn refs/heads/v1.0


Can I push it back to the remote, so that this link would be available for other user checking out from remote the next time?

Answer

The short answer is no. The transfer protocols do not support symbolic references in any significant and useful way. The HEAD symbolic reference has partial support in newer versions of Git, through git remote set-head, but only in the "obtain information from remote" direction, not in the "send information to remote" direction.

This is not actually a big loss, as symbolic references are really only well-behaved for the special name HEAD. In particular, if you ask Git to delete your example green_horn name, it will delete v1.0 rather than green_horn! (I consider this a bug myself, but I'm not sure if the Git maintainers think of it as a bug or a feature.)

In order to set or manipulate a symbolic reference, then, you must have some other form of access to the remote. This is why, for instance, GitHub provides a non-Git interface (browser / REST API) to adjust the target of the HEAD symbolic reference of a GitHub-hosted repository.


Terminology note: That's not an alias (which in Git refers specifically to git alias and the [alias] configuration section), it's a symbolic reference. (I was a bit confused until I read through the entire question, since you do call it both things.)