ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[Git查看、删除、重命名远程分支和tag](http://blog.zengrong.net/post/1746.html) # 重命名远程分支 在git中重命名远程分支,其实就是先删除远程分支,然后重命名本地分支,再重新提交一个远程分支。 例如下面的例子中,我需要把 devel 分支重命名为 develop 分支: ~~~ $ git branch -av * devel 752bb84 Merge pull request #158 from Gwill/devel master 53b27b8 Merge pull request #138 from tdlrobin/master zrong 2ae98d8 modify CCFileUtils, export getFileData remotes/origin/HEAD -> origin/master remotes/origin/add_build_script d4a8c4f Merge branch 'master' into add_build_script remotes/origin/devel 752bb84 Merge pull request #158 from Gwill/devel remotes/origin/devel_qt51 62208f1 update .gitignore remotes/origin/master 53b27b8 Merge pull request #138 from tdlrobin/master remotes/origin/zrong 2ae98d8 modify CCFileUtils, export getFileData ~~~ 删除远程分支: ~~~ $ git push --delete origin devel To git@github.com:zrong/quick-cocos2d-x.git - [deleted] devel ~~~ 重命名本地分支: `git branch -m devel develop` 推送本地分支: ~~~ $ git push origin develop Counting objects: 92, done. Delta compression using up to 4 threads. Compressing objects: 100% (48/48), done. Writing objects: 100% (58/58), 1.38 MiB, done. Total 58 (delta 34), reused 12 (delta 5) To git@github.com:zrong/quick-cocos2d-x.git * [new branch] develop -> develop ~~~ 然而,在 github 上操作的时候,我在删除远程分支时碰到这个错误: ~~~ $ git push --delete origin devel remote: error: refusing to delete the current branch: refs/heads/devel To git@github.com:zrong/quick-cocos2d-x.git ! [remote rejected] devel (deletion of the current branch prohibited) error: failed to push some refs to 'git@github.com:zrong/quick-cocos2d-x.git' ~~~ 这是由于在 github 中,devel 是项目的默认分支。要解决此问题,这样操作: 进入 github 中该项目的 Settings 页面; 设置 Default Branch 为其他的分支(例如 master); 重新执行删除远程分支命令。 # GIT与远程REPOSITORY同步TAG和BRANCH [参考](http://smilejay.com/2013/04/git-sync-tag-and-branch-with-remote/) 某个分支在远程库中已经删除了,直接用"git fetch"是不能将远程已经不存在的branch等在本地删除的 解决办法 ~~~ git fetch --prune #这样就可在本地删除在远程不存在的branch man git-fetch --prune After fetching, remove any remote tracking branches which no longer exist on the remote. -t, --tags Most of the tags are fetched automatically as branch heads are downloaded, but tags that do not point at objects reachable from the branch heads that are being tracked will not be fetched by this mechanism. This flag lets all tags and their associated objects be downloaded. #另外,关于git branch的几个命令 git branch # 查询本地存在的branch git branch -r # 查询远程的branch git branch -a # 查询本地和远程branch git branch -d -r origin/todo #删除远程的todo branch ~~~