Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7665613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:37:01+00:00 2026-05-31T14:37:01+00:00

I had a mistake and commit some changes to git which I should not

  • 0

I had a mistake and commit some changes to git which I should not have committed.
After I made the commit, I pushed my changes.
I then used the following commands to try and reset my changes.

 git reset --hard head

Now I want to push this ‘reset’ to the remote repository with this command:

git push MyBranch

But I am getting this error:

remote: error: denying non-fast-forward refs/heads/branch (you should pull first)

I tried to use this command without any success:

git push -f "origin" 

Any idea what I can do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:37:02+00:00Added an answer on May 31, 2026 at 2:37 pm
    git push -f origin myBranch 
    

    should work (provided you are aware this can be dangerous if MyBranch was already fetched by others in their own repo)

    Since 2012, you also have:

    • git push --force-with-lease (Git 1.8.5+ Q3 2013) which is safer, and
    • git push --force-if-includes (Git 2.30+, Q1 2021), which attempts to ensure that what is being force-pushed was created after examining the commit at the tip of the remote ref that is about to be force-replaced.

    Note: if your remote repo (‘origin’) has its config set with

    receive.denyNonFastForwards true
    

    it will deny any non fast-forward push (even when forced).
    See "Is there a way to configure git repository to reject ‘git push –force’?".


    The OP user654019 reports

    I managed to solve the problem this time by setting denyNonFastForwards to false and using -f to force the push

    If the OP didn’t have access to the repo, he/she would have to:

    • reset the local HEAD to its original position (see "Recover from git reset --hard?"):
      git reset HEAD@{1}
    • make a new commit which cancel your merge, as described in the ProGit book, with git revert:
      git revert -m 1 HEAD~ (in your case)

    By example:

    $ git revert -m 1 [sha_of_C8]
    Finished one revert.
    [master 88edd6d] Revert "Merge branch 'jk/post-checkout'"
     1 files changed, 0 insertions(+), 2 deletions(-)
    

    revert a merge

    A complete discussion on how to revert a merge can be found here.

    The idea remains to generate only new commits, including one reverting the changes introduced by the merge commit.
    You then can push that new commit, as a fast-forward change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

it had a existing git checkout and had made some modifications, then i checked
UPDATE!!! Suggested answer is NOT correct, my mistake. The #container DIV should've had float:left;.
My colleague has pushed to our git repository a mistake. I wish to commit
EDIT: I had made a mistake during the debugging session that lead me to
I had a discussion with some colleagues mentioning that there are not too many
I have committed a few source files to my git repository and tagged it
I made a mistake with my git repositories(edited files from the main one), and
Edit: My original example had a silly mistake. After fixing it I still get
After executing a big query (it is my mistake: I had only 1Gb of
EDIT: Solved it! I made stupid mistake, I had a textureId I'd forgotten about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.