I am separating one git repo into 3. I've used Detach (move) subdirectory into separate Git repository to separate folder and pushed them successfully to new git repos. On the existing repo, I've used the following command to clear out the moved directories.
git filter-branch -f --index-filter "git rm -q -r -f --cached --ignore-unmatch lib/xxx/$REPO" --prune-empty HEAD
Now when I do git st
on the original repo, I get :
# On branch 1.5.0
nothing to commit (working directory clean)
When i try to git push
, I get:
! [rejected] 1.5.0 -> 1.5.0 (non-fast-forward)
error: failed to push some refs to '[email protected]:/xxx/.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
My guess is to use -f : git push -f origin <branch>
but I wish to make sure since this is going to modify my existing repo.
Your use of filter branch has made your repository different to the remote. So as you observe, the remote rejects your push with a warning about this. In this case you are planning to forcibly change the repository to match your filtered version so you can go ahead and push with the force flag. You shouldn't change published repositories like this -- but you can if you want to. Bear in mind anyone who has a clone needs notifying - but if there aren't any others - then go ahead.
If you want to be really careful - make a another clone of the original now. Then do your push. If something ends up wrong - for can always force it back using push --mirror
from the backup repository.