Several posts talk about removing a file or directory from GIT - but they don't go as far as explaining how to PUSH those changes into the main repository.
For example, this works just fine to remove the directory but when I try to PUSH this change to the main Git repo, I am denied:
! [rejected] master -> master (non-fast forward)
error: failed to push some refs to '/repo/project.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again. See the 'non-fast forward'
section of 'git push --help' for details.
What is the last step to actually push this to the main repo and actually remove that directory?
Nick Lewis' answer is sufficient, but I just want to add some emphasis, more than will fit in a comment. Here's a quote from the
git filter-branch
man page:Italics emphasis added - that's pretty important. Filter-branch really does rewrite history, it'll screw up anyone who's cloned/pulled from your repo, and it's scary. You should really know all that before you give it a go. Most people here are pretty good about providing that reminder whenever they recommend
filter-branch
orrebase
; I think it's appropriate to have a pretty strong repetition of it here, on a question where the answer ispush --force
in order to completely rewrite the history in your public repo. That's a scary operation.When you remove something so aggressively, you rewrite history. Therefore, the upstream repository is rejecting your change because it would result in a loss of history. In this case, you will need to use