Luther Baker Luther Baker - 5 months ago 36
Git Question

How to commit after removing a directory from GIT

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?


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

git push --force