{"id":15355950,"url":"https://github.com/fibo/cleanup_git_branches","last_synced_at":"2026-01-24T12:10:21.428Z","repository":{"id":53823081,"uuid":"521610058","full_name":"fibo/cleanup_git_branches","owner":"fibo","description":"remove unused git branches with one command","archived":false,"fork":false,"pushed_at":"2024-05-28T16:17:38.000Z","size":7,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T06:39:03.919Z","etag":null,"topics":["branches","git"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/fibo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-08-05T11:19:43.000Z","updated_at":"2024-07-12T08:22:41.000Z","dependencies_parsed_at":"2025-04-15T06:48:02.241Z","dependency_job_id":null,"html_url":"https://github.com/fibo/cleanup_git_branches","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fibo/cleanup_git_branches","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Fcleanup_git_branches","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Fcleanup_git_branches/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Fcleanup_git_branches/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Fcleanup_git_branches/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fibo","download_url":"https://codeload.github.com/fibo/cleanup_git_branches/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2Fcleanup_git_branches/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28727391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T10:24:43.181Z","status":"ssl_error","status_checked_at":"2026-01-24T10:24:36.112Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["branches","git"],"created_at":"2024-10-01T12:26:22.381Z","updated_at":"2026-01-24T12:10:21.421Z","avatar_url":"https://github.com/fibo.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cleanup_git_branches\n\n\u003e Remove unused git branches\n\n[![KLP](https://fibo.github.io/svg/badges/klp.svg)](https://fibo.github.io/kiss-literate-programming)\n\n## Usage\n\nSimply launch the following command in a git repo\n\n```sh\ncleanup_git_branches\n```\n\n## Installation\n\nBoth *zsh* and *bash* shell are supported.\n\nJust copy and paste the `cleanup_git_branches` function below in your shell profile or (assuming you are using zsh) do something like\n\n```sh\nmkdir -p ~/.shell\ncd ~/.shell\ngit clone https://github.com/fibo/cleanup_git_branches.git\necho \"source ~/.shell/cleanup_git_branches/fun.sh\" \u003e\u003e ~/.zshrc\n```\n\nWith the setup above, to update run the following\n\n```sh\ncd ~/.shell/cleanup_git_branches\ngit pull origin main\nsource ~/.zshrc\ncd -\n```\n\n## Annotated source\n\nTo generate sources, enter this repo folder and run `make`.\n\nCreate a `cleanup_git_branches` function\n\n    cleanup_git_branches() {\n\nGet current working branch and repo default branch.\n\n      WORKING_BRANCH=`git rev-parse --abbrev-ref HEAD`\n      DEFAULT_BRANCH=`basename $(git symbolic-ref refs/remotes/origin/HEAD)`\n\nGo to default branch.\n\n      if [ \"$DEFAULT_BRANCH\" != \"$WORKING_BRANCH\" ]; then\n        git switch $DEFAULT_BRANCH\n      fi\n\nRemove local branches (excluding main branch) that are already merged.\n\n      git branch --merged | grep -v $DEFAULT_BRANCH | while read branch\n      \tdo\n      \t\tgit branch -d $branch\n      \tdone\n\nRemove local branches with no remote reference.\n\n      git fetch -p\n      for BRANCH_NAME in $(git branch -v | grep '\\[gone\\]' | awk '{print $1}')\n      \tdo\n      \t\tgit branch -D $BRANCH_NAME\n      \tdone\n\nBack to previous branch.\n\n      if [ \"$DEFAULT_BRANCH\" != \"$WORKING_BRANCH\" ]; then\n        git switch $WORKING_BRANCH\n      fi\n    }\n\n\n## Tip\n\nIf you need to change default branch, once done remotely (for instance on GitHub), you need\nto update your local repository.\nAssuming the new default branch is `main`, launch\n\n```sh\ngit symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main\n```\n\n## License\n\n[MIT](https://fibo.github.io/mit-license)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffibo%2Fcleanup_git_branches","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffibo%2Fcleanup_git_branches","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffibo%2Fcleanup_git_branches/lists"}