新建本地分支

  1. git checkout -b branch_name

删除本地分支

  1. git branch -d branch_name

将本地分支推送到远程,并将本地分支绑定到远程分支

  1. git push --set-upstream origin branch_name

删除远程分支

  1. git push origin –-delete branch_name

查看本地和远程分支

使用 git branch -a 命令可以查看所有本地分支和远程分支(git branch -r 可以只查看远程分支)

有时候,发现很多在远程仓库已经删除的分支在本地依然可以看到。

使用命令 git remote show origin,可以查看 remote 地址,远程分支,还有本地分支与之相对应关系等信息。

  1. git remote show origin
  2. * remote origin
  3. Fetch URL: git@192.168.20.70:ai-compiler-group/runtime.git
  4. Push URL: git@192.168.20.70:ai-compiler-group/runtime.git
  5. HEAD branch: fast_develop
  6. Remote branches:
  7. develop tracked
  8. fast_develop tracked
  9. fast_develop_all_commit_bertrelease tracked
  10. master tracked
  11. refs/remotes/origin/bert_layerNorm_debug stale (use 'git remote prune' to remove)
  12. refs/remotes/origin/bert_qkv_baseline stale (use 'git remote prune' to remove)
  13. vgg19_dev tracked
  14. vgg19_dev_aligned tracked
  15. Local branches configured for 'git pull':
  16. crds_xxw merges with remote crds_xxw
  17. cv_release_check_tool merges with remote cv_release_check_tool
  18. cv_release_dynamic_shape merges with remote cv_release_dynamic_shape
  19. Local refs configured for 'git push':
  20. cv_release_dynamic_shape pushes to cv_release_dynamic_shape (up to date)
  21. fast_develop_all_commits pushes to fast_develop_all_commits (up to date)
  22. fdac_xxw pushes to fdac_xxw (up to date)

此时我们可以看到那些远程仓库已经不存在的分支,例如:

  1. refs/remotes/origin/bert_layerNorm_debug stale (use 'git remote prune' to remove)
  2. refs/remotes/origin/bert_qkv_baseline stale (use 'git remote prune' to remove)

根据提示,使用 git remote prune origin 命令:

  1. git remote prune origin
  2. Pruning origin
  3. URL: git@192.168.20.70:ai-compiler-group/runtime.git
  4. * [pruned] origin/bert_layerNorm_debug
  5. * [pruned] origin/bert_qkv_baseline

这样就删除了那些远程仓库不存在的分支。git branch -vv结果如下:

  1. crds_xxw 077acf0 [origin/crds_xxw: gone] [feat] add ioctl to release process
  2. cv_release_check_tool da1f60a [origin/cv_release_check_tool: gone] change test_exe as a check tools to show device details
  3. cv_release_dynamic_shape bbfc2e9 [origin/cv_release_dynamic_shape] [fix] incorrect error string in runtime_strerror()
  4. fast_develop_all_commits bbfc2e9 [origin/fast_develop_all_commits] [fix] incorrect error string in runtime_strerror()
  5. fast_develop_all_commits_performance 63975b3 [origin/fast_develop_all_commits_performance: ahead 6, behind 39] feat: add opcode_csr_en_cache opcode_csr_rc and opcode_csr_wc for odma csr config
  6. fast_develop_all_commits_t 20d024b [origin/fast_develop_all_commits_t: gone] update print debug info
  7. fast_t_xxw 77aa6d5 [origin/fast_t_xxw: gone] [fix] read devices with id greater than 255
  8. fast_xxw_input_output_no32M 8b43189 [origin/fast_xxw_input_output_no32M: gone] [fix] no 32M limit for input/output in DDR
  9. * fdac_xxw aa82f84 [origin/fdac_xxw] [feat] add ioctl to release process
  10. fdac_xxw_32m_limit 22c1d73 [origin/fdac_xxw_32m_limit: gone] [fix] 512M limit for input/output and 32M limit for weight

其中, crds_xxw 077acf0 [origin/crds_xxw: gone] [feat] add ioctl to release process
表示分支crds_xxw的远程分支origin/crds_xxw已经不存在了。

https://blog.csdn.net/qq_16885135/article/details/52777871