Trimming branches that were deleted in the Git repository above but still exist in my fork

I created a fork of the git repository on BitBucket (call him fork_origin ). Now the upstream repository (let it be called upstream_origin ) has many branches, merged into it by the master and deleted. So run

 git fetch --prune upstream_origin 

removed many branches of remote/upstream_origin/ , but now the same branches still exist in the remote/fork_origin/ .

Is there a standard git command to handle this? I would like to stay away from complex bash scripts that massively delete remote repositories.

UPDATE:

As suggested, I tried using the prune remote command command:

 git remote prune fork_origin 

However, this had no effect. With further research, this only works for "obsolete" branches, but when I run:

 git remote show fork_origin 

this shows that all branches are still β€œtracked”. Therefore, it makes sense that the git remote prune command did not have anything obsolete to remove. Is there a way to force the remote repo ( fork_origin ) to update its branch statuses relative to upstream_origin ?

+7
source share
3 answers

If you want to delete branches on a remote computer, use the following command:

 git remote prune fork_origin 

But before that, take a look at this thread and see what might go wrong: git remote prunes - as many abbreviated branches did not appear as I expected

+1
source

There are no git commands, but you will need to:

  • fetch fork_origin
  • identify any remotes/fork_origin/branch that is no longer present in remotes/upstream_origin (due to your git fetch --prune upstream_origin )
  • git push --delete thoseBranches

This is a bit like " Delete multiple deleted branches in git .

0
source

For Linux and Mac users, this command will remove all branches from my work that were removed in the upstream.

 git branch -a | grep origin | awk -F \/ '{print $NF}' > _my_branches.txt; git branch -a | grep upstream | awk -F \/ '{print $NF}' > _upstream_branches.txt; for deleted_branch_name in `comm -23 _my_branches.txt _upstream_branches.txt`; do git push origin :$deleted_branch_name; done 

If you prefer to take steps instead of one long command:

 # Find the branches in my fork git branch -a | grep origin | awk -F \/ '{print $NF}' > _my_branches.txt; # Find the branches still in upstream git branch -a | grep upstream | awk -F \/ '{print $NF}' > _upstream_branches.txt; # See only the ones that are still in my fork with the comm command # And only for those branches issue a git command to prunbe them from my fork. for deleted_branch_name in `comm -23 _my_branches.txt _upstream_branches.txt`; do git push origin :$deleted_branch_name; done 
0
source

All Articles