I have two remote repositories in Bitbucket and Github that have been set up to sync master branch from Bitbucket to Github (one-way sync) by running this shell script regularly:
git clone --mirror https://$bitbucket_url/repo.git $REPO
cd $REPO
git remote add --mirror=fetch github https://$GIT_TOKEN@$github_url/repo.git
git fetch origin
git push --tags github master
The synchronisation has been doing its job well but it started to get rejected recently with the following error (real git token and github url have been masked below):
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://$GIT_TOKEN_MASKED@$github_url/repo.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.
Based on the error message, I understand that there are commits on Github that Bitbucket doesn't have? So I need to do a git pull from github before git push? I did attempt that but it was complaining that I can't do git pull because there is no working tree. Any ideas how I can fix this?