Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,707
Community Members
 
Community Events
184
Community Groups

Refresh local branches (automatically remove local branches that were deleted on remote)

Hi!

I've deleted a branch in my remote repository, but sourcetree keeps showing it in the list of local branches. Is there any way Sourcetree automatically remove the local branch if it was already deleted in the remote repository?

Thanks

4 answers

1 accepted

12 votes
Answer accepted
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.
Jan 15, 2018

You need to do a Fetch and check the box to prune tracking branches, that will remove branches that you have removed on the remote.

This will only remove Branches under "Remote" and not my "Local" Checked out (now remotely deleted) Branches, yes?

If so: How I can "Prune" my Local branches?

Like # people like this
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.
Sep 18, 2018

@Johannes Sebastian Correct, the fetch will only affect remote branches. To delete local branches you have to right-click on it and select Delete... Note that you can only delete branches that are not checked out.

Like # people like this

Thank you for a quick response.

That is the answer I was expecting. Remote actions will not affect my local branches.

I am sure there is are good arguments for this....

However, that is what I need.

It is a small feature and I hope SourceTree will offer it in the future :)

Like # people like this

Might I add, because I just spent about 15 minutes trying to figure out why I don't see a checkbox about pruning. If you are right clicking with the mouse in the left panel under remotes on the origin itself to perform the fetch operation, the popup for additional checkboxes does not appear. If you click the fetch button at the top menu of the app, then you do see the popup of additional checkboxes. So not a bug, just a useability thing.

Like Steve Letch likes this

Thanks, this is what I was looking for :)

This cannot be done automatically from within SourceTree UI but you can run the following command on git cmd:

git branch -vv | grep ': gone]' | grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -D

You can create your own alias too:

git config --global alias.delete-gone-branches "! git branch -vv | grep ': gone]' | grep -v \"*\" | awk '{ print \$1; }' | xargs -r git branch -D"

And then run it git delete-gone-branches.

Sources:

Mac, bitbucket

open my project and open terminal

run 

git branch -vv | grep ': gone]' | grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -D

the branches are still on remote when using source tree

gitsourcetree.jpg

they are not there when looking on the web

gitweb.jpg

close and open source tree 

Like atj393 likes this

My answer deletes LOCAL branches that are no longer present on remote.
You're referring to REMOTE branches in your local SourceTree - that's different.

To delete these remote branches from your SourceTree you have to fetch remote repo with "Prune tracking branches no longer present on remote(s)".

SourceTree.png

git branch | grep -v develop | xargs git branch -d

This Works 

Don't ever run this command, you might delete ALL your local branches!

As @Mikael Sandberg mentioned, you can use "Fetch" and tick "Prune tracking branches no longer present on remotes" to sync remote branches.

For local branches, even though there is no automatic way, there is a way quicker than clicking through all unwanted branches.

Just click "Branch" 

then select "Delete Branches"

then tick all unwanted local branches

and select delete branches

Voila, done.

Please note you can also delete remote branches here, even force delete them -- just be careful :) 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events