3

Followed these steps to remove some content from my repository.

However, when I did a git push, I got the below message:

Writing objects: 100% (28/28), 6.72 KiB | 1.34 MiB/s, done. Total 28 (delta 18), reused 18 (delta 9) remote: error: denying non-fast-forward refs/heads/master (you should pull first) remote: error: denying non-fast-forward refs/heads/multiplicity_refinement (you should pull first) To ssh://path_to_repo/repo_name.git ! [remote rejected] master -> master (non-fast-forward) ! [remote rejected] multiplicity_refinement -> multiplicity_refinement (non-fast-forward) error: failed to push some refs to 'ssh://path_to_repo/repo_name.git'

Al Fahad
  • 2,378
  • 5
  • 28
  • 37
Di Yao
  • 31
  • 1
  • 2
  • 1
    Please include the steps that you had taken with git in your answer (instead of in a link). The idea is that SO questions are independent and will be a resource for others in the future, even after the link is broken. – ncke Oct 31 '18 at 19:17

1 Answers1

4

By default, Git refuses to push any commits to an existing branch if doing so would lose commits already pushed. When you use BFG Cleaner or any other tool that rewrites your history, the commits you've made are rewritten and appear different from the existing commits (which they are). If you're sure you want to push those changes anyway, you'd need to use the --force flag: git push --force origin master.

You can run git push --help to see more information about --force and why it's necessary.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • You don't use a branch name like `master` with beg. You checkout a mirror and then push to all branches once you filter/delete what you need from the project's history. – rjurney Apr 29 '20 at 20:46
  • Yes, the point was to illustrate the use of the `--force` option and its placement. Presumably the author knew about the ability to push multiple branches because they had done so and the default in modern versions of Git is to push only the current branch. – bk2204 Apr 29 '20 at 22:49