简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM