Beginner... I have a local repo which files I use for a website on a remote server. These files I also keep as a remote repo on Bitbucket. The local saved files I changed and made huge errors on so I downloaded from the website server the known working files and saved in my local files.
I'm now trying to push these known working files to Bitbucket but I'm having issues and error messages as 'refusing to merge unrelated histories' and 'Updates were rejected because the tip of your current branch is behind its remote counterpart'.
As I state at the start I'm a beginner and know I may not of done things in the correct procedure but I'm learning. I'm not necessarily after the 'answer' but would appreciate some guidance.
I'll my best to provide a proper answer. When you want to push commits to the server you have to make sure that both the remote and local repositories have the same set of commits.
If the remote has a few commits more than your local branch, then you will get errors when you try to push your files to the remote. In such cases, you need to perform a fast-forward by either pulling or re-basing the extra commits.
From the errors that you have mentioned, I believe the following might fix the errors. I'm assuming you are committing files to the master
branch.
git fetch origin master
Before you go to the next step, please make sure that your working directory is clean (i.e there are no untracted or modified files). If not, you can either commit the changes or stash them.
git rebase origin/master
Now, when you perform a rebase
you may get merge-conflicts. If you do get merge-conflicts you'll have to resolve them. On the other hand if you don't get any merge-conflicts you can proceed to push the files to remote.
If however you get merge-conflicts please try the following -
git status
This will present you with all the files that have merge-conflicts. You'll have to go to all the files and resolve the conflicts. After you are done with that, you have to add all the files that you had changed while fixing the merge-conflicts.
git add -A
And then you can continue with the rebase -
git rebase --continue
Hopefully, after going through these steps you should be able to push your files to remote. Please do note that there are other ways to resolve merge-conflicts. I use the method mentioned above.