{"id":16370771,"url":"https://github.com/integralist/go-gitbranch","last_synced_at":"2025-10-12T15:43:25.251Z","repository":{"id":140160918,"uuid":"323400167","full_name":"Integralist/go-gitbranch","owner":"Integralist","description":"Personal project for moving complex bash script to a go application","archived":false,"fork":false,"pushed_at":"2020-12-26T13:38:09.000Z","size":21,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-24T19:55:18.603Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","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/Integralist.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}},"created_at":"2020-12-21T17:11:07.000Z","updated_at":"2022-01-12T10:40:00.000Z","dependencies_parsed_at":"2023-04-07T13:04:38.437Z","dependency_job_id":null,"html_url":"https://github.com/Integralist/go-gitbranch","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Integralist/go-gitbranch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Integralist%2Fgo-gitbranch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Integralist%2Fgo-gitbranch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Integralist%2Fgo-gitbranch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Integralist%2Fgo-gitbranch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Integralist","download_url":"https://codeload.github.com/Integralist/go-gitbranch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Integralist%2Fgo-gitbranch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011855,"owners_count":26085005,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-10-11T03:05:56.992Z","updated_at":"2025-10-12T15:43:25.220Z","avatar_url":"https://github.com/Integralist.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-gitbranch\n\nSimple command line abstraction for managing git branches.\n\n- `gitbranch create`: create a branch.\n- `gitbranch checkout`: checkout a branch.\n- `gitbranch delete`: delete a branch.\n- `gitbranch rename`: rename a branch.\n\n```\ngitbranch create --help\n\nUsage of create:\n  -branch string\n        branch to create\n\ngitbranch checkout --help\n\nUsage of checkout:\n  -branch string\n        branch to checkout\n\ngitbranch rename --help\n\nUsage of rename:\n  -branch string\n        branch to rename\n  -name string\n        new branch name\n  -normalize\n        whether to normalize the given branch name\n  -prefix\n        whether to generate a unique prefix for the branch name\n\ngitbranch delete --help\n\nUsage of delete:\n  -branch string\n        branch to delete\n```\n\nWhen creating a branch we automatically modify the branch name to have unique prefix: \n\n```\n\u003cusername\u003e_\u003cyyyymmdd\u003e_\u003cbranch_name_with_hyphens_replaced_by_underscores\u003e\n```\n\nThis is the same logic used when renaming a branch and passing the `--prefix` and/or `--normalize` flags. \n\n\u003e Note: the 'username' part can be controlled by setting the environment variable `GITBRANCH_PREFIX`.\n\n## Why?\n\nThis isn't just a pointless veil over the porcelain `git` commands (I'm _very_ comfortable with git). \n\nFirstly, each subcommand (when used without the relevant flags) will display a _filtered_ and _mutated_ list of branches and will enable a user to select a branch to interact with by specifying a unique identifying branch number. This (for me) is quicker than typing out a full branch name (especially as I dynamically generate branch names with both a username prefix and date combination).\n\nYou might be wondering why I even need to type out a full branch name manually when there is git autocomplete? Well, nearly every command I use I put inside a bash shell `alias` which means the git autocomplete no longer works! So, as I dynamically generate a rather long git branch, typing that out manually is _tedious_ to say the least.\n\nI had this code already written in my `.bashrc` but realized that updating my esoteric bash scripting logic (the more complicated scripting was done to handle the filtering/numerical prefixing) wasn't going to be maintainable in the long term. It worked, but if I needed to make any changes then it was going to be much harder to remember how it all worked.\n\nOn top of that bash scripting doesn't lend itself to code reuse like a more robust 'general programming' language. This means, although the golang equivalent is more code it's ultimately easier to work with than the more _complex_ bash script equivalent.\n\nI then create alias' in `.bashrc` to this binary and the various subcommands exposed:\n\n```bash\n# gitbranch is my own custom abstraction over the various git branch operations\n#\n# Download:\n# https://github.com/Integralist/go-gitbranch/releases\n#\nalias gbr=\"gitbranch rename -prefix -normalize\"\nalias gc=\"gitbranch checkout\"\nalias gcb=\"gitbranch create\"\nalias gcm=\"gitbranch checkout -branch master\"\nalias gbd=\"gitbranch delete\"\n```\n\n\u003e Note: refer to my [dotfiles](https://github.com/Integralist/dotfiles).\n\n### The trouble with git alias\n\nThe issue with git related alias' losing autocomplete is possible to workaround, but not without some caveats.\n\nHere's the code necessary to get autocomplete to work:\n\n```bash\nalias g=\"git\"\n__git_complete g _git\nalias gb=\"git branch\"\n__git_complete gb _git_branch\nalias gc=\"git checkout\"\n__git_complete gc _git_checkout\nalias gu=\"git push\"\n__git_complete gp _git_push\nalias gd=\"git pull\"\n__git_complete gp _git_pull\n```\n\nBut the `__git_complete` command is lazy loaded internally by the bash shell, so calling it from within shell configuration files (e.g. `.bash_profile` and `.bashrc`) will cause an error as the command isn't yet loaded. It's not possible to access the function either because it's an _internal_ (i.e. _private_) function as far as the bash shell is concerned.\n\nTo workaround _that_ issue, you'll need to grab the code yourself from the bash source code! See: https://github.com/git/git/blob/master/contrib/completion/git-completion.bash which of course is an ugly manual step to have to take.\n\nNow you've _still_ got to remember the various flags because (using the above alias' as an example) imagine you want to delete a branch. You execute `gb -\u003cTab\u003e` expecting to see a bunch of flags like `-D` for deleting a specified branch but you in fact get nothing!? You have to use the `--` flag equivalent (e.g. `gb --\u003cTab\u003e` and then you'll see `--delete` as a possible option).\n\nBut there's still problems with the fact that only `--` flag equivalents have tab completion (and this is just an issue with git completion in general and not related to alias'). The biggest issue is that there is no long form flag equivalent to `git checkout -b` if you want to create a branch and check it out in one command you can only use `-b` and so you have to remember it as there's no autocomplete for it.\n\n## RELEASES\n\nA release is generated automatically via the [`goreleaser-action`](https://github.com/goreleaser/goreleaser-action) which is triggered whenever a semver git tag is pushed (e.g. `git tag v1.0.0 -m \"v1.0.0\" \u0026\u0026 git push origin v1.0.0`).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintegralist%2Fgo-gitbranch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintegralist%2Fgo-gitbranch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintegralist%2Fgo-gitbranch/lists"}