Git Delete Stale Branch
Description:Permalink
So I had an issue the other day where I ran git branch -va
and saw a bunch of branches that existed locally and not on the remote server. Here is what you do to fix this to get them back in sync.
To Resolve:Permalink
-
First list my current branches
1 2 3 4 5
me@server.domain.com:/home/myuser/my-repo (main) $ git branch MySprint_1.3 MySprint_1.6 * main
-
Then list just the remotes
1 2 3 4
me@server.domain.com:/home/myuser/my-repo (main) $ git branch -r origin/HEAD -> origin/main origin/main
-
Now remove stale branches from remote and then delete all the branches local that don’t match up:
1 2 3 4 5 6
me@server.domain.com:/home/myuser/my-repo (main) $ git remote prune origin URL: git@ssh.dev.azure.com:v3/organization/project/repo * [pruned] origin/Sprint_1.3 $ git branch -D MySprint_1.3 # Deleted branch MySprint_1.3 (was 510ce91).
Comments