History Integration Issues with git Commits
I have a remote repo, and now working on local files for Video Production.
After I was done with saving my changes on the local version, I decided to push the committed changes to remote repository. I got errors on both git push and git pull.
# Error: failed to push
Push was rejected because the tip of my current branch is behind that of remote.
Error given was: ‘failed to push’
Solution: Integrate the remote changes by pulling from remote before pushing.
I pulled from remote:
# Error: fatal : refusing to merge unrelated histories
Solution: Merging unrelated histories in git
git pull origin main — allow-unrelated-histories
This command will solve the unrelates histories fatal error.
After that, you can fix merge conflicts in your files if any. Save, commit and then push:
git commit -am 'Resolve merge conflict' && git push
Or go straight to merging:
git merge origin origin/main
Then push your changes to remote:
This is all you need to do.
Sometimes you might need to use — allow-unrelated-histories on the merge instead of on the pull as we did here.
If this issue of unrelated history occurs to you frequently, do this instead:
- When creating a new repo on Github, do not check the README.md box.
- It is better to do git clone, instead of creating a local repository to avoid parallel histories altogether.