Search code examples
gitgithubgerrit

What is refs/for/master when not using Gerrit?


If I understand correctly, refs/for/ is a special namespace that's used in Gerrit for uploading changes.

However, out of habit, instead of git push origin master, I've just done git push origin HEAD:refs/for/master on a non-Gerrit repo, which apparently worked:

$ git push origin HEAD:refs/for/master
Enumerating objects: [...]
[...]
To github.com:fstanis/myrepo.git
 * [new branch]      HEAD -> refs/for/master

This apparently created a new branch on origin, but this branch isn't listed when I try git branch -r and isn't shown in GitHub's UI. What exactly happened here? Where do commits pushed to refs/for/master "go" when not using Gerrit?


Solution

  • When you pushed refs/for/master reference to remote you have created new namespace for references, ang gave it name for.

    Long story short, it allows to create default subset of references for each user to operate on and avoid name conflicts for refs used by different groups of repository users.

    Users can set their own configuration in remote.remote_name.fetch and remote.remote_name.push configuration values so that most common operations with branches and tags (pull, push, fetch etc.) would use their preferred namespace instead of default one defined by repository owner.

    Maybe it is easier to understand if you think that git creates its own hardcoded namespaces when you create repository with all default configuration, one for branches (heads) and one for tags (tags) so that you do not need to prefix your branch and tag names in every operation with branches or tags