Problem Description
I have gotten myself into a gitpickle. This image illustrates the situation I've put myself in:
Unsurprisingly, I now can't push the green commits, because the non-fast-forward updates are rejected. On the remote, I tried to checkout the dev branch so I could do the git reset --hard HEAD~1
command to obliterate the commit on the remote, but it is a bare repo so I can't checkout the dev branch. The current branch is always "master." My goal is simply to remove the red commit on the remote so I can push the green commits.
Question
How can I remove the red commit on the remote dev branch without having to check out the dev branch on the remote?
Notes
- I don't want to force the push because other repos pull from the remote and I don't want to break them. However, I know that nobody has pulled from the remote yet, so I'm okay with just removing the red commit.
- I now see that in the future, I should use the
git revert
command instead when a commit that needs to be undone has already been pushed. - I also have a master branch, release branches, and various feature branches that I've left out to simplify the image. Let me know if they're relevant and I'll add them.
Related Questions
I've looked at these questions (and many more), but I don't think they address my current question because either I don't see how I can apply their solutions to remove a commit on a remote, or they don't work for bare repos.
What does "Git push non-fast-forward updates were rejected" mean?
How to undo last commit(s) in Git?
How can I fast-forward a branch without checking it out
Rebase a branch without checking it out