Git push -f is being rejected for unprotected branches

Viewed 124

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.

2 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

Under any circumstances you should never force a push on a remote git repository, you are risking to lose some changes you didn't have on your local machine.

As for the issue, it may be due to a fact that you're pushing to a different branch with unrelated histories, happens when you initialize git locally and the default branch is master but the remote branch when you make a new repository is main, so you can't push from this to that as it's unrelated history.

Related