Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push after git filter-branch rejected

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.

like image 466
rahul Avatar asked Nov 17 '11 09:11

rahul


People also ask

How to force the git push?

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).

What is the purpose of git filter 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 .

Why is git push being rejected?

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.


1 Answers

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.

like image 120
patthoyts Avatar answered Sep 20 '22 08:09

patthoyts