{"id":23228900,"url":"https://github.com/lingyansi/ck","last_synced_at":"2025-07-20T01:06:55.000Z","repository":{"id":50309092,"uuid":"110967485","full_name":"LingYanSi/ck","owner":"LingYanSi","description":"git分支快速切换 git branch switches quickly","archived":false,"fork":false,"pushed_at":"2022-07-28T06:19:10.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T18:41:50.528Z","etag":null,"topics":["branch","checkout","git"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LingYanSi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-16T12:13:17.000Z","updated_at":"2022-07-28T06:19:13.000Z","dependencies_parsed_at":"2022-09-05T16:41:07.984Z","dependency_job_id":null,"html_url":"https://github.com/LingYanSi/ck","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LingYanSi/ck","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LingYanSi%2Fck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LingYanSi%2Fck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LingYanSi%2Fck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LingYanSi%2Fck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LingYanSi","download_url":"https://codeload.github.com/LingYanSi/ck/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LingYanSi%2Fck/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266052541,"owners_count":23869475,"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":["branch","checkout","git"],"created_at":"2024-12-19T01:15:32.121Z","updated_at":"2025-07-20T01:06:54.785Z","avatar_url":"https://github.com/LingYanSi.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# ck\ngit分支快速切换\n\n当你本地有很多分支时，如果你想快速在分支间切换，只需输入分支名的一部分即可\n\n\n## 使用\n```bash\nck mas # 可切换到master分支\n```\n\n## 安装\n在`.zshrc`文件内添加如下代码\n\n```bash\nfunction ck() {\n    branchName=$1\n\n    # 参数为空\n    if [ -z $branchName ]; then\n        git branch\n        return 0\n    fi\n\n    # 切回到最近分支\n    if [ \"$branchName\" = \"-\" ]; then\n        git checkout $branchName\n        return 0\n    fi\n\n    if [ \"$2\" = \"-a\" ]; then\n        git fetch\n        allBranch=`git branch -r`\n        realBranch=`echo $allBranch | grep -i $branchName | sed -n '1p' | xargs`\n\n        # 删除remotes/origin/前缀\n        # https://stackoverflow.com/questions/13210880/replace-one-substring-for-another-string-in-shell-script\n        realBranch=${realBranch/origin\\//}\n        # https://unix.stackexchange.com/questions/346679/no-coprocess-error-when-using-read\n        # https://unix.stackexchange.com/questions/198372/read-command-in-zsh-throws-error\n        printf '%s ' \"是否切换到远程分支 $realBranch y/n:\"\n        read yes\n\n        if [ \"$yes\" = \"y\" ] || [ \"$yes\" = \"yes\" ]; then\n            git checkout $realBranch\n            return 0\n        fi\n    else\n        # https://stackoverflow.com/questions/11392189/how-to-convert-a-string-from-uppercase-to-lowercase-in-bash\n        # branchName=$(echo $branchName | tr '[:upper:]' '[:lower:]')\n        allBranch=`git branch`\n        # allBranch=$(echo $allBranch | tr '[:upper:]' '[:lower:]')\n        # https://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-a-bash-variable\n        # grep -i 忽略大小写\n        realBranch=`echo $allBranch | grep -i $branchName | sed -n '1p' | xargs`\n\n        git checkout $realBranch\n\n        if [ -z $realBranch ]; then\n            echo \"本地不存在 $branchName 相关分支，正在为您查找相关远程分支\"\n            ck $branchName -a\n            return\n        fi\n    fi\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flingyansi%2Fck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flingyansi%2Fck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flingyansi%2Fck/lists"}