Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't push to a repo after rebase

I’m having some trouble with git rebase. I have forked a public repository. In my fork I have a master branch and a feature branch. I have developed and committed code in feature and now I create a pull request directly into the upstream repository.

But, by the time I am ready to create a pr, the upstream master has already merged new commits. So I need to update my local repo before the pr can go through. To do this I checkout into master and run gh repo sync origin my-github/the-repo. I then git pull. After I checkout to feature and run rebase master. This works smoothly, no problems here. The problem is when I try to push changes to the remote feature. I get the following error:

 ! [rejected]            squares-of-id -> squares-of-id (non-fast-forward)
error: failed to push some refs to 'https://github.com/my-github/the-repo'
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.

Can someone help explain why my local ends up behind my remote? And hopeful provide a fix?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

By rebasing you rewrite the history and as a result your local history does not match anymore with the upstream’s history. Public branches should never be rewritten as that might cause lots of problems downstream.

However, if this is your personal branch it is fine and you can force the server to accept your commits/history by invoking git push --force-with-lease

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading