Renigunda Renigunda - 3 months ago 210
Git Question

Unable to Push repository files to Remote Repository (GitHub)

I am new to Git & GitHub,

I have a local repository named HackerRank
I have a remote repository https://github.com/xxx/HackerRank.git

Now i wanted to push my local repository to remote repository.

I have used the following commands

git remote add hacker https://github.com/xxx/HackerRank.git
git push hacker master


It throwed the error

To https://github.com/xxx/HackerRank.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/xxx/HackerRank.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.


So now i tried to pull from my remote repository using the following command

git pull hacker master
From https://github.com/xxx/HackerRank
* branch master -> FETCH_HEAD
* [new branch] master -> hacker/master
fatal: refusing to merge unrelated histories


Now i tried to fetch using the following command

$ git fetch hacker
From https://github.com/xxx/HackerRank
* [new branch] master -> hacker/master


Now i tried to merge using the following command

$ git merge hacker/master
fatal: refusing to merge unrelated histories


Please suggest me.

Answer

You can try to rebase your local branch on remote master branch and push it : git pull --rebase hacker master

You also can try to do a squash merge with git merge --squash hacker/master

Comments