17

I've a repository for my dotfiles and went to push changes from a branch only to encounter...

$ git push
Enumerating objects: 46, done.
Counting objects: 100% (46/46), done.
Writing objects: 100% (46/46), 3.20 MiB | 1.52 MiB/s, done.
Total 46 (delta 0), reused 0 (delta 0)
To gitlab.com:auser/dotfiles.git
 ! [remote rejected] kimura -> origin/kimura (deny updating a hidden ref)
 ! [remote rejected] master -> origin/master (deny updating a hidden ref)
error: failed to push some refs to 'git@gitlab.com:auser/dotfiles.git'

This thread suggests its because pull requests made on origin and links to a blog post with solution of how to skip this, although I do not explicitly have refs/pull in the path thats being rejected so it may be a different issue but I couldn't find much info on this so figured I try the proposed solution and updated my config to...

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
     url = git@gitlab.com:auser/dotfiles.git
     fetch = +refs/heads/*:refs/heads/*
     fetch = +refs/tags/*:refs/tags/*
     fetch = +refs/change/*:refs/change/*
     pushurl = git@gitlab.com:auser/dotfiles.git
     push = +refs/heads/*:refs/remotes/origin/*
[submodule "oh-my-zsh/.oh-my-zsh"]
     url = https://github.com/robbyrussell/oh-my-zsh
     active = true
[branch "master"]
     remote = origin
     merge = refs/heads/master
     pushRemote = origin
[branch "kimura"]
     remote = origin
     merge = refs/heads/kimura
     fetch = +refs/heads/*:refs/heads/*
     fetch = +refs/tags/*:refs/tags/*
     fetch = +refs/change/*:refs/change/*

But the problem persists. My branches are...

$ git branch -a
* kimura
  master
  remotes/origin/kimura
  remotes/origin/master

The host I'm trying to push from is where I started the repo before mirroring to Gitlab.

Francisco Puga
  • 23,869
  • 5
  • 48
  • 64
slackline
  • 2,295
  • 4
  • 28
  • 43
  • 4
    `push = +refs/heads/*:refs/remotes/origin/*` should be `push = +refs/heads/*:refs/heads/*` in common cases. – ElpieKay Jan 24 '19 at 10:30
  • Thanks, thats progress, I'm now being told I'm not allowed to push to protected branches, I've only protected master but have resolved that. No idea how the config was set in that manner. – slackline Jan 24 '19 at 11:20
  • 3
    @slackline doesn't this mean that your question has been solved? If so, it's pretty misleading that there's no accepted answer - perhaps you could self-answer and formally close this out – snugghash Oct 08 '21 at 00:46

2 Answers2

2

I had the same error

[remote rejected] origin/myBranch   (deny updating a hidden ref)

The problem was:

I cloned a remote repo mobile into a folder, then, I made modifications on the code, and when I tried to push, instead of pushing the local repo mobile to the remote one, I was trying to push its parent

enter image description here

The right way was to open git bash inside the local repo you have cloned and execute the right commands, this may be your problem too.

enter image description here

Francisco Puga
  • 23,869
  • 5
  • 48
  • 64
Mohammed NAIMI
  • 177
  • 1
  • 11
0

The SO thread you're referencing concerns a repo cloned as --mirror. This is most probably not your situation.

A mirror clone is one that is intended to be a local hub for pushing, and not for direct work (e.g., it doesn't have a working tree, active branch etc.). Regular repo clones fetch branch xyz into, say, origin/xyz - to avoid changing the branch you're working on from under your feet. In mirror clones you want to fetch xyz into xyz directly. I suspect the 'protected branch' error you're getting is due to exactly this: git is protecting you from fetching into the branch you're currently working on.

I'm guessing the correct config for you would be -

[remote "origin"]
        url = git@gitlab.com:auser/dotfiles.git
        fetch = +refs/heads/*:refs/remotes/heads/*
        fetch = +refs/tags/*:refs/remotes/tags/*
        fetch = +refs/change/*:refs/remotes/change/*
        pushurl = git@gitlab.com:auser/dotfiles.git
        push = +refs/heads/*:refs/heads/*
...
[branch "kimura"]
        remote = origin
        merge = refs/heads/kimura
        fetch = +refs/heads/*:refs/remotes/heads/*
        fetch = +refs/tags/*:refs/remotes/tags/*
        fetch = +refs/change/*:refs/remotes/change/*

And please verify that you actually need the push key. I don't see why the defaults won't be enough for a regular clone.

Ofek Shilon
  • 14,734
  • 5
  • 67
  • 101