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.
To force a push to only one branch, use a + in front of the refspec to push (e.g git push origin +master to force a push to the master branch).
git-filter-branch can be used to get rid of a subset of files, usually with some combination of --index-filter and --subdirectory-filter .
A commit gets rejected and causes a failed to push some refs to error because the remote branch contains code that you do not have locally. What this means is that your local git repository is not compatible with the remote origin. Based on the above, your local machine is missing commits C and D.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With