Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git push -f is being rejected for unprotected branches

Tags:

git

gitlab

We have our own GitLab server running and have imported an older project into it. This project has a strange behavior, which seems not to be the default for projects on the gitlab.com server: If a merge request requires a local rebase, it is not possible to force push git push —force-with-lease to the remote branch after the rebase.

! [remote rejected]     feature_branch -> feature_branch (non-fast-forward)
error: failed to push some refs to 'server.de:group/project.git'

The remote branch is unprotected, and the force push should work in principle. It seems not related to any GitLab configuration but the configuration of the old GitLab project.

Does anyone know how to reconfigure the remote configuration? I don't even know what to look for. A colleague of mine found this answer here:

https://www.reddit.com/r/git/comments/50td21/comment/d76urb5/

But I don't find (can't read) this file on the remote server. Any help would be appreciated.

like image 263
Kokookster Avatar asked Oct 15 '25 13:10

Kokookster


1 Answers

Unless the logs include any clue, you need to check the configuration in the remote repository on your on-premise GitLab server, in the folder referenced by your repository storage (for instance /home/git/repositories/...).

cd /home/git/repositories/<namespace>/<myRepo.git>
git config -l
# with a recent enough Git
git config -l --show-scope --show-origin

Check if you have any settings which might prevent the push, like receive.denyNonFastforwards.

git config --show-scope --show-origin receive.denyNonFastforwards

The OP confirms in the comments

First, I had to understand that all project paths were hashed and can be found under /var/opt/gitlab/git-data/repositories/@hashed.
The hashes are in the UI admin area under the corresponding project.

Using the hashed path, I found the config file with denyNonFastforwards.
I changed that using git config --file config receive.denynonfastforwards false.

However, this changed the owner to root, and no pushes worked at all.
So I had to change back owner to git by using chown git: config. After that, everything worked as expected.

like image 71
VonC Avatar answered Oct 18 '25 02:10

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!