Git: Remove tracking branches no longer on remote

Short version:

Use this command:

 


Original answer:

 

After the command

removes the remote references, when you run

it will show ‘gone’ as the remote status. For example,

So you can write a simple script to remove local branches that have gone remotes:

Note that the above uses the “porcelain” command git branch to get the upstream status.

Another way to obtain this status is to use the “plumbing” command git for-each-ref with the interpolation variable %(upstream:track), which will be [gone] just like above.

This approach is somewhat safer, because there is no risk of accidentally matching on part of the commit message.

 

 

From: https://stackoverflow.com/a/33548037/2559229

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注