How do I clean up previously tracked branches in SourceTree?

Richard Quadling
Contributor
May 30, 2018

I've got several branches that I've worked on that have been tracked on origin.

The branches have been merged into master and have been deleted on origin.

If I use the 'Fetch' option and select the 'Purge' option, I can see that branches that have been removed on origin.

But the list of branches I see locally still exist.

I can see that at this stage, there's no difference between a local branch that has not been pushed to origin and a branch that had previously been pushed to origin but is now deleted on origin.

Is there a way to keep this in sync in some way?

By that I mean, if the branch is deleted on origin, then really delete it locally, including the tracking branch data (I think that's what the list of branches is in SourceTree under WORKSPACE - not the Remote branches).

I'm on MacOS using SourceTree 2.7.3 (169) with the dark theme.

4 answers

3 votes
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 30, 2018

Git has a default disposition of keeping data unless it’s explicitly thrown away. Prune will only remove the remote-tracking references, not the local branch itself.

There is a request to have the feature to sync removed remote branches with local ones, SRCTREEWIN-8631. This one if for Windows, I could not find one for Mac, but add a comment that you would like to see this functionality on Sourcetree for Mac too.

Andreas Beer June 19, 2019

at least adding some icon that indicates "remote has been deleted" would be convenient for the manual cleanup.

Schroef
Contributor
August 16, 2019

Why wouldnt they make the same functionality also available for OSX. I dont understand why this would need to be requested for OSX users separatly, makes no sense with development in mind.

Like Richard Quadling likes this
1 vote
mirandali1020 July 28, 2019

Agree. As the dev lead, I have way too many branches on my local, where they are all closed from origin. It would be nice if I can clean those up with a single command.

0 votes
Richard Quadling
Contributor
September 8, 2021

Thanks ... I ended up with

```alias git-clean-branches='git branch --merged|egrep -v "(^\*|master|develop|staging)" | xargs git branch -d'```

0 votes
nawazibrahim
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 8, 2021
git branch | grep -v develop | xargs git branch -d

This works 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events