I have done the below steps:
>git checkout remote-branch-test
>git pull
>git checkout remote-branch
>git pull
>git merge remote-branch-test
Automatic merge failed; fix conflicts and then commit the result.
resolved the conflict
>git add .
>git commit
>git push origin remote-branch
**! [remote rejected] remote-branch -> remote-branch (you are not allowed to upload merges)
error: failed to push some refs to ....
When I do a git status on my remote server
>git status
On branch remote-branch
Your branch is ahead of 'origin/remote-branch' by 37 commits.
(use "git push" to publish your local commits)
I am not able to push the changes to remote
what I am missing here?
CodePudding user response:
There are several things to note here. phd pointed out the most important:
[remote rejected] ... you are not allowed to upload merges
This tells us that your "remote"—the other Git to which you're sending commits—simply forbids all merge commits, period.
That particular error message, however, comes not from Git or GitHub, but from Gerrit. See Gerrit: remote rejected (you are not allowed to upload merges) even though I allowed "Push merge commit" for example. This implies that you're not using GitHub for your pushes. Hence the github tag is probably inappropriate. And, since Gerrit adds its own layer of stuff atop Git, the git tag may be inappropriate too. I added gerrit here, but you should make sure these are the correct tags and delete any inappropriate ones.
Finally, it's normal for a merge to add many commits: merge commits have two parents, and therefore adding one merge commit to some branch B will often add N 1 commits to B, where N is the number of commits reachable from the commit being merged but not from B itself before the merge. So your merge merged an existing 36 commits, plus the merge itself, for 37 commits total.
CodePudding user response:
Solve the problem by following Steps :
git fetch
git checkout origin/remote-branch
git merge --squash origin/remote-branch-test
git commit
git push origin HEAD:refs/for/remote-branch