RockBoro
RockBoro

Reputation: 2473

get refuse to merge error when I run "git pull origin master"

following a pluralsight course to create a visual studio code extension.

but getting an error when setting up the github repository. When I run "git pull origin master" I get error "refusing to merge unrelated histories"

here are the git commands I run after yo code runs and creates the extension:

git add .
git commit -m "Initial Commit"

create the repo up on github

git remote add origin https://github.com/lae0901/static-site-hero.git
git push origin master
git pull origin master

github is totally confusing to me. How to merge origin and master?

thanks,

here are all the steps I am running: open a node.js command prompt in windows

-- run yo code to create the extension

yo code

? What type of extension do you want to create? New Extension (JavaScript)
? What's the name of your extension? static site hero
? What's the identifier of your extension? static-site-hero
? What's the description of your extension? static site hero
? What's your publisher name (more info: https://code.visualstudio.com/docs/tools/vscecli#_publishing-extensions)? lae0
901
? Initialize a git repository? (Y/n) Y

-- cd to the extension directory

cd static-site-hero

git status
git add .
git commit -m "Initial Commit"

login to github.com create a new repository set name to name of the extension. add license - MIT click "create repository" click the download dropdown to find the url of the repo

git remote add origin https://github.com/lae0901/static-site-hero.git

-- check that configed correctly:

git remote --verbose

-- this is what is displayed

C:\Users\Steve\static-site-hero>git remote --verbose
origin https://github.com/lae0901/static-site-hero.git (fetch)
origin https://github.com/lae0901/static-site-hero.git (push)

-- first I git push origin master. But that fails:

C:\Users\Steve\static-site-hero>git push origin master

To https://github.com/lae0901/static-site-hero.git

! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/lae0901/static-site-hero.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.

-- and then the git pull origin master fails also

C:\Users\Steve\static-site-hero> git pull origin master

warning: no common commits remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From https://github.com/lae0901/static-site-hero * branch master -> FETCH_HEAD * [new branch] master -> origin/master fatal: refusing to merge unrelated histories

How to correct this error? Why refuse to merge unrelated histories?

Upvotes: 0

Views: 2406

Answers (1)

Mark
Mark

Reputation: 92440

This is happening because the Github repository has an initial commit that you made when you created the license. That license commit is not in your local branch so GitHub thinks you have two unrelated projects and you can't push or pull. Ideally you wound not start with a commit on GitHub before you've pushed your repo to it. All is not lost though.

You can pull the commit from Github and tell it to ignore unrelated histories with:

git pull origin master --allow-unrelated-histories

This will merge in the license to your local branch. Then you should be able to push to Github.

Upvotes: 3

Related Questions