1

I've accidentally done a Gerrit style push on a GitLab repo.

That is, while on my local branch I did:

$ git push origin HEAD:refs/for/master
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 3.06 KiB | 184.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0), pack-reused 0
To gitlab.domain-name.com:project-name.git
 * [new reference]   HEAD -> refs/for/master

When what I should have done was a simple:

$ git push -u origin branch-name

This reference does not show anywhere on the GitLab web GUI as far as I can tell.

How can I undo this? Do I need to?

Toby
  • 9,696
  • 16
  • 68
  • 132

2 Answers2

4

You can delete the reference on the remote with the following command:

git push -d origin refs/for/master

Full demo:

$ git ls-remote
From git@gitlab.domain.tld:repository.git
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    HEAD
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    refs/heads/master

$ git push origin HEAD:refs/for/master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 286 bytes | 286.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To gitlab.domain.tld:repository.git
 * [new branch]      HEAD -> refs/for/master

$ git ls-remote
From git@gitlab.domain.tld:repository.git
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    HEAD
a5b0640960e5a1f26e784d2f93f94f0ec29d5f51    refs/for/master
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    refs/heads/master

$ git push -d origin refs/for/master
To git@gitlab.domain.tld:repository.git
 - [deleted]         refs/for/master

$ git ls-remote
From git@gitlab.domain.tld:repository.git
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    HEAD
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    refs/heads/master
Matt
  • 12,848
  • 2
  • 31
  • 53
1

Git refspec uses two refs (source)

  • refs/heads to track local branches.
  • refs/remotes/ to track remote branches.

refs/for/ is a Gerrit specific namespace and so should not affect your repo since you are not using a Gerrit server. (source)

Amit Singh
  • 2,875
  • 14
  • 30
  • This is great contextual info in addition to the method in @Matt's answer, thanks Amit! – Toby Jun 01 '21 at 15:09