Reputation: 4405
I can't find a reson for being able to push changes in any branch other than master. I mean, I have master branch which I created by pushing my code to gitlab. Than, any tentative to push a change to master branch fails. Nevertheless, I duplicated my master branch with another branch named develop and on it I can push my changes. To make simple, let me put all I am doing after googling for while:
C:\dev\test>git fetch --all
Fetching origin
C:\dev\test>git reset --hard origin/master
HEAD is now at 64031f0 just created by generator
... some changes via my editor ....
C:\dev\test>git commit -a -m "changed project name"
[master 5abf2f2] changed project name
1 file changed, 5 insertions(+), 5 deletions(-)
C:\dev\test>git push -u origin/master
fatal: 'origin/master' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
C:\dev\test>git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 365 bytes | 365.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Error: This is the master branch, and the commit has no merge request
remote: 64031f03f1723e3399ad467dbbb536942fe144f0 5abf2f29e0ced51289d1fcd684b1510acd354764 refs/heads/master
To ssh://gitlab.mycomp.net:2222/myportfolio/mycomp-app-sf-just-test.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'ssh://[email protected]:2222/myportfolio/mycomp-app-sf-just-test.git'
C:\dev\test>git push -u origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 365 bytes | 365.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Error: This is the master branch, and the commit has no merge request
remote: 64031f03f1723e3399ad467dbbb536942fe144f0 5abf2f29e0ced51289d1fcd684b1510acd354764 refs/heads/master
To ssh://gitlab.mycomp.net:2222/myportfolio/mycomp-app-sf-just-test.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'ssh://[email protected]:2222/myportfolio/mycomp-app-sf-just-test.git'
In few words, most of answers I saw around tells either to use git push -u or to unprotect the branch. Now my gitlab project branch is unprotected and as you can see I am using -u
Upvotes: 4
Views: 21515
Reputation: 121
The issue here is by default master branch is protected one. You can change that setting if you want to using "Unprotect" button under Repository settings -> Protected branches. Also, you can change branch accessibility settings for merge , push for maintainer, developer level too. Refer screen for more detail.
Upvotes: 12
Reputation: 9987
Your problem is probably related to how permissions work with Gitlab.
If you go down the list of my linked doc, you'll see that:
Push to protected branches
is only allowed to people having Maintainer (was Master prior to 11.0) and Owner permissions.
can't find a reson for being able to push changes in any branch other than master
This is because only master is protected by default. Therefore, you would need elevated permissions in order to push directly on that branch.
Upvotes: 4
Reputation: 83557
It appears that GitLab does not allow you to push directly to master
. This is a common practice. Instead, you should create a merge request from your feature branch to master. When you accept the merge request in the GitLab UI, it will automatically create a merge commit and move the master
branch.
Upvotes: 3