git push --force gitlab master
Enumerating objects: 50, done.
Counting objects: 100% (50/50), done.
Delta compression using up to 8 threads
Compressing objects: 100% (29/29), done.
Writing objects: 100% (40/40), 12.22 KiB | 4.07 MiB/s, done.
Total 40 (delta 26), reused 18 (delta 11)
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To gitlab.com:xxx/yyyy.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:xxx/yyyy.git'
What should I do to push my commits to Gitlab? I use several remotes, and other remotes are OK and I was able to finish
git push --force some_other_remote master
If you have a look at Git's official documentation, you will quickly notice that you can force this command. You can use the --force flag (or -f for short). This can look like an easy workaround when the git push command does not work, but it is rarely recommended — it's not the default behavior for a reason.
Force-pushing is a highly threatening and risky method if you're working in a common repository. Using this force pushing you should be able to force your local revision to the remote repository. But forcefully pushing to remote repo is not a good practice.
From the official documentation on dealing with Protected Branches:
Following the steps above, you should be greeted with a box similar to this one below.
There, you can click either:
for the branch you want to force push to, e.g., master
.
If you don't want to navigate through the navigation bars, you can also fill out this URL template:
https://gitlab.com/<USERNAME>/<PROJECTNAME>/settings/repository#js-protected-branches-settings
and replace <USERNAME>
and <PROJECTNAME>
with your specific username and project name, respectively.
Note, the "Allowed to force push" button is probably favored over un-selecting the Unprotect button because branch protection gives you additional safety from accidentally deleting your branch. But either option appears to work.
More help:
As the GitLab documentation states: By default, a protected branch does four simple things:
So you need to unprotect the branch temporarily. Finally, return it to its original state.
For doing that :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With