lewis4u lewis4u - 1 month ago 9
Git Question

Git - different commits each, respectively. (use "git pull" to merge the remote branch into yours)

My goal is to get rid of one file in all my commits on github so i did next steps:

I have filtered my branch with this command:

git filter-branch --index-filter 'git rm --cached --ignore-unmatch [file_name]' HEAD


to delete one single file in all commits and now after running

git status


it asks me to pull,

ubuntu@ubuntu:/var/www/html/laravel/app_folder$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 18 and 18 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean


but i don't want to pull. I'm afraid that if i pull i will have this file again in my commits.

Shouldn't i push it now so the changes take effect on my git hub....i don't know what to do.

Answer

Yes, you should push... probably.

git filter-branch rewrites history... except it doesn't rewrite it, it creates a new history.

To explain, if your repository looked like this, with the master branch on commit E as well as origin.

A -- B -- C -- D -- E [master]
                      [origin/master]

Then after you ran git filter-branch those commits will have been rewritten into new commits. But the origin (on Github) will still be the same.

A -- B -- C -- D -- E  [origin/master]
 \
  -- B1 - C1 - D1 - E1 [master]

They have "diverged". This is what git status is telling you. Your master is not a child of origin/master.

Usually this means that you've made local changes to master while other people have pushed changes to origin's master. So it's telling you to pull other people's changes.

But this is incorrect. You're overwriting history. So you should git push your new version of master. Except git won't allow you to do that for safety reasons, so you have to git push --force.