{"id":24506172,"url":"https://github.com/pvdb/git-branch--stray","last_synced_at":"2025-10-16T07:12:42.992Z","repository":{"id":56874240,"uuid":"152106853","full_name":"pvdb/git-branch--stray","owner":"pvdb","description":"Delete local \"remote-tracking\" branches for which the tracked branch no longer exists on the remote","archived":false,"fork":false,"pushed_at":"2025-02-27T18:21:57.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-05T19:08:10.581Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pvdb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-08T15:52:45.000Z","updated_at":"2025-02-27T18:22:02.000Z","dependencies_parsed_at":"2022-08-20T22:30:21.395Z","dependency_job_id":null,"html_url":"https://github.com/pvdb/git-branch--stray","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvdb%2Fgit-branch--stray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvdb%2Fgit-branch--stray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvdb%2Fgit-branch--stray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvdb%2Fgit-branch--stray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pvdb","download_url":"https://codeload.github.com/pvdb/git-branch--stray/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253809653,"owners_count":21967767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-21T23:33:24.312Z","updated_at":"2025-10-16T07:12:37.944Z","avatar_url":"https://github.com/pvdb.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# List and delete \"stray\" git branches\n\n## Summary\n\nRun `git branch--delete--stray` to delete local tracking branches for which the remote branch being tracked has been deleted on the remote... use `git branch--list--stray` to just list them; both work best with [regular pruning](#pruning) of remote-tracking references!\n\n## Background\n\nGit has a default disposition of keeping data unless it's explicitly thrown away; this extends to _(unnecessarily?)_ holding onto references to so-called local \"remote-tracking\" branches where the branch being tracked has long since been deleted on the remote itself.\n\nThis utility refers to these local tracking branches as \"stray\" branches, and includes two git extensions: one for listing all \"stray\" branches, and a second one for _(selectively)_ deleting them.\n\nIn case of the [GitHub Flow](https://guides.github.com/introduction/flow/) for instance, a local branch would become \"stray\" after a pull request gets merged and the underlying remote branch gets deleted... after the next `git fetch` it would be possible to identify the \"stray\" branch with something akin to `git branch --list --merged`, and delete them accordingly.\n\nBut that's not the only scenario that results in \"stray\" branches, which is why the various \"solutions\" you find on Stack Overflow don't typically cover all edge cases, whereas this utility does; it also prefers git plumbing over git porcelain, and it implements most of its logic in a library, making it very straightforward to implement even more git extensions for dealing with \"stray\" branches.\n\n## What's in a name?\n\nIn the context of this utility, a branch is considered \"stray\" if it is what git calls [a \"remote-tracking\" branch](https://git-scm.com/book/id/v2/Git-Branching-Remote-Branches#_tracking_branches), but one where the remote branch it was tracking no longer exists _(ie. where the branch it was tracking has been deleted on the remote, e.g. on GitHub or on Bitbucket)_.\n\nThe term \"stray\" was chosen to avoid confusion with existing git terminology like ''merged\", \"tracked\" and even \"orphaned\".\n\nAlso, the names of the two git extensions implemented by this utility:\n\n* `git branch--list--stray`\n* `git branch--delete--stray`\n\n... were chosen two mimic some existing `git branch` options:\n\n* `git branch --list --merged`\n* `git branch --delete`\n\nrespectively.\n\n## Installation\n\n    gem install git-branch--stray\n\n## Usage\n\nAfter installing the gem, you will have two new git extensions in your environment: `git-branch--list--stray` will list all stray branches, whereas `git-branch--delete--stray` will iterate over the list and - after prompting for confirmation - delete any stray branches.\n\nBecause they will be in your local `$PATH` you can run them as so-called git subcommands, as follows:\n\n```\ngit branch--list--stray\ngit branch--delete--stray\n```\n\nMost likely, though, you will want to create some [git aliases](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases) to make it easier to work with the two utility scripts:\n\n```\ngit config --global alias.bls branch--list--stray\ngit config --global alias.bds branch--delete--stray\n```\n\nAlternatively, a similar approach can be used to add either of the scripts to your existing git aliases and/or git utility scripts.\n\n## Pruning\n\nThe two git extensions work best if your git workflow includes regular pruning of remote-tracking references that no longer exist on the remote, either by running [`git fetch --prune`](https://git-scm.com/docs/git-fetch#git-fetch--p) when syncing with the remote in question, or else configuring [git's pruning behaviour](https://git-scm.com/docs/git-fetch#_pruning) for your environment.\n\n## Extending\n\nMost of the utility is implemented in a Ruby library, making it very easy to use the logic for dealing with \"stray\" branches in your own Ruby applications or utilities.\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'git-branch--stray'\n```\n\nAnd then execute:\n\n    $ bundle\n\nThe library to require is in the [`lib/git/branch/stray.rb`](lib/git/branch/stray.rb) file.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/pvdb/git-branch--stray.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpvdb%2Fgit-branch--stray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpvdb%2Fgit-branch--stray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpvdb%2Fgit-branch--stray/lists"}