I keep getting the following error when I try to push to Bitbucket. I used to work just fine and it just stop working.
Can someone please help me understand what does this mean and how to solve it?
Pushing to https://x-token-auth@bitbucket.org/UserName/project-name.git
To https://bitbucket.org/UserName/project-name.git
= [up to date] Redesign -> Redesign
= [up to date] Version4.0 -> Version4.0
= [up to date] version2.0 -> version2.0
= [up to date] version3.0 -> version3.0
= [up to date] version3.2 -> version3.2
= [up to date] version4.1 -> version4.1
= [up to date] version5.0.3+cocoapods-firebase -> version5.0.3+cocoapods-firebase
= [up to date] version5.1 -> version5.1
= [up to date] version5.2 -> version5.2
= [up to date] version5.3 -> version5.3
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://x-token-auth@bitbucket.org/UserName/project-name.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
FYI - I'm not sure how to use git pull
as suggested in the error. Also, I'm using git-tower as my git GUI.
Why: The error occurs due to the fact that remote
holds a newer version of master than local
. In this case git forbids to push to the branch because - what will be merged and how and who resolves the conflicts? Someone always has to be responsible, the repository can not do this job on its own.
Git forces you to pull
first - pull
being equivalent to fetch
+merge
- so you collect the newest version of the code to your local
and by doing so inherit the responsibility to merge in your code and resolve the merge conflicts that you created by writing your code. Otherwise it would be possible to just offload them to remote
and leave a mess behind with no owner.
What to do: git pull
. You will receive a message asking you to do a merge. In case of a merge conflict you will be asked to resolve it with any tool of your choice (git tower in your case I suppose).
After that fast forward pushes will be possible again until someone pushes to master again and the branch again holds a newer version of the common code base than your local
.
How to get around it:...(partly)... On Bitbucket and Github you can deploy restrictions to push to certain branches. This is called 'protecting branches'. By doing so you can forbid everyone to push to the protected branches and proceed on a white-list basis. You can define restrictions for pushing, e.g. no merge commits on this branch, mandatory pull requests before merging etc. This will stop people from randomly pushing to production branches and rule out major sources for issues.