Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First Git Push Rejected

When i type git push origin master the following error message is shown from git:

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

Then, i type git fetch origin , git merge origin master & git pull origin master the following error message is shown from git:

From https://github.com/farrasdoko/RumahSakit
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

How to push it??

like image 701
Farras Doko Avatar asked Aug 25 '18 00:08

Farras Doko


1 Answers

hint: Updates were rejected because the tip of your current branch is behind

Often when that happens, what you'd really like to do is to add the additional commits in origin/master into your branch before your own commits. You can use the rebase command to do that:

git rebase origin/master

That will pull the new commits from origin into your branch and then add your own new commits on top, so that your commits are the latest. You may encounter some conflicts while rebasing. When that happens, git will stop and tell you to resolve the conflicts; after that, you should git add the affected files and then git rebase --continue. Or, if you decide you don't know how to deal with the problem, you can git rebase --abort and your branch will be returned to the same state it was in before the git rebase command started.

git rebase is a powerful command that can make a quick mess of your branch, so be careful with it, but don't be afraid of it. Standard computing advice applies: back up your work before doing anything if you're not confident. Luckily, it's easy to just make a new branch as a backup (git checkout -b my_backup_branch) and then switch back to your working branch.

like image 176
Caleb Avatar answered Oct 04 '22 12:10

Caleb