History Integration Issues with git Commits

unrelated git histories

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.

git push
# 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:

git pull
# 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:

git push

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.

--

--

--

think&code. Also an occasional G(Foodie)OAT: https://www.instagram.com/anaikoki/

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What are Serverless Components?

CycloneDX Ruby Gem

What’s New in Neo4j-GraphQL-Java

Nuvola Integrates Repeat & Shuffle Status, Adjusts to New Deezer Design, And More

Simplifying animations using batch updates on iOS

5 Things in the first year of a Software Engineer

NECKTIE KNOTS AND MATHEMATICS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anna Ikoki

Anna Ikoki

think&code. Also an occasional G(Foodie)OAT: https://www.instagram.com/anaikoki/

More from Medium

Getting started with Git/Github.

GIT and GITHUB A BEGINNERS GUIDE

Git and GitHub (Part-2)

Getting started with git and Github