Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rejected updates on branch tip when trying to rebase HEAD pointer

Tags:

git

I wanted to reset the HEAD pointer to my previous commit

$ git reset --hard HEAD~1

HEAD moved to previous commit, however, unable to push to my origin master

$git push origin master

! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'https://github.com/username/repo.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
    hint: before pushing again.

How do I move my pointer and tell Git to update the changes?

like image 524
Christopher Smith Avatar asked Nov 12 '12 23:11

Christopher Smith


People also ask

How do you fix updates were rejected because the tip of your current branch is behind hint its remote counterpart?

The updates were rejected because the tip of your current branch is behind error can be fixed by pushing to a remote branch. This process is called a Git push, and it debugs the errors of the current branch, which is also known as a local branch.

When should you avoid rebasing a branch in git?

If you use pull requests as part of your code review process, you need to avoid using git rebase after creating the pull request. As soon as you make the pull request, other developers will be looking at your commits, which means that it's a public branch.


1 Answers

By default, Git does not allow you to push changes which do not have the most recent change on the server in their history. This is to avoid problems if someone else has already pulled your previous HEAD; then you pushing something that is not a descendent will mean that they will need to merge or rebase onto your new commit.

If you know that no one else is using your repo, or have communicated with everyone who is, then you can forcibly push your changes:

git push -f origin master

Some servers are configured not to allow forcible updates. If they don't, you may be able to get around it by deleting and recreating the branch:

git push origin :master
git push origin master

But only do these if you know that no one else is basing their work off of yours, or you can communicate to everyone who is and ensure that they properly reset to the previous commit in their local repos as well.

like image 95
Brian Campbell Avatar answered Oct 14 '22 08:10

Brian Campbell