Home > Software design >  Git force push --force --all does not update all branches
Git force push --force --all does not update all branches

Time:03-19

I am doing a hard delete of a file in my gitlab repo. I have 3 branches where i want this file to be removed from the commits.

My understanding with git is not that great

I have run the below command to completely remove any reference of a particular file from all of branches in my repo and they are all rewritten.

git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch fileA.sh" -- --all

i ran then ran the below commands to clean up the repo on my local

rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

Below are the branches that I hae , along side the remote-tracking branches

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/master
  remotes/origin/mbyousaf2020-master-patch-95874
  remotes/origin/test

However, when running the git push --all --force it is only updating the master branch on my repo. How do I also update the remaining remote-tracking branches?

:qabash $ git push --all --force
Enumerating objects: 316, done.
Counting objects: 100% (316/316), done.
Delta compression using up to 12 threads
Compressing objects: 100% (114/114), done.
Writing objects: 100% (314/314), 30.10 KiB | 10.03 MiB/s, done.
Total 314 (delta 195), reused 276 (delta 188)
remote: Resolving deltas: 100% (195/195), completed with 1 local object.
To gitlab.com:qa.git
   a28475e...40053dd master -> master (forced update)

What command do i need to run that it updates all my branches and completely removes any reference of the file in all my branches?

CodePudding user response:

You gave the answer yourself, when you listed the branches:

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/master
  remotes/origin/mbyousaf2020-master-patch-95874
  remotes/origin/test

The remotes/origin branches are not yours; they are remote-tracking branches. You only have one branch — master. Therefore git push --all pushes all the branches you have, namely that one branch, master. Git is behaving exactly as expected.

I have 3 branches where i want this file to be removed from the commits.

No, you don't. You yourself have proved that you have only one branch, namely master.

  • Related