新建本地分支
git checkout -b branch_name
删除本地分支
git branch -d branch_name
将本地分支推送到远程,并将本地分支绑定到远程分支
git push --set-upstream origin branch_name
删除远程分支
git push origin –-delete branch_name
查看本地和远程分支
使用 git branch -a
命令可以查看所有本地分支和远程分支(git branch -r
可以只查看远程分支)
有时候,发现很多在远程仓库已经删除的分支在本地依然可以看到。
使用命令 git remote show origin
,可以查看 remote 地址,远程分支,还有本地分支与之相对应关系等信息。
❯ git remote show origin
* remote origin
Fetch URL: git@192.168.20.70:ai-compiler-group/runtime.git
Push URL: git@192.168.20.70:ai-compiler-group/runtime.git
HEAD branch: fast_develop
Remote branches:
develop tracked
fast_develop tracked
fast_develop_all_commit_bertrelease tracked
master tracked
refs/remotes/origin/bert_layerNorm_debug stale (use 'git remote prune' to remove)
refs/remotes/origin/bert_qkv_baseline stale (use 'git remote prune' to remove)
vgg19_dev tracked
vgg19_dev_aligned tracked
Local branches configured for 'git pull':
crds_xxw merges with remote crds_xxw
cv_release_check_tool merges with remote cv_release_check_tool
cv_release_dynamic_shape merges with remote cv_release_dynamic_shape
Local refs configured for 'git push':
cv_release_dynamic_shape pushes to cv_release_dynamic_shape (up to date)
fast_develop_all_commits pushes to fast_develop_all_commits (up to date)
fdac_xxw pushes to fdac_xxw (up to date)
此时我们可以看到那些远程仓库已经不存在的分支,例如:
refs/remotes/origin/bert_layerNorm_debug stale (use 'git remote prune' to remove)
refs/remotes/origin/bert_qkv_baseline stale (use 'git remote prune' to remove)
根据提示,使用 git remote prune origin
命令:
❯ git remote prune origin
Pruning origin
URL: git@192.168.20.70:ai-compiler-group/runtime.git
* [pruned] origin/bert_layerNorm_debug
* [pruned] origin/bert_qkv_baseline
这样就删除了那些远程仓库不存在的分支。git branch -vv
结果如下:
crds_xxw 077acf0 [origin/crds_xxw: gone] [feat] add ioctl to release process
cv_release_check_tool da1f60a [origin/cv_release_check_tool: gone] change test_exe as a check tools to show device details
cv_release_dynamic_shape bbfc2e9 [origin/cv_release_dynamic_shape] [fix] incorrect error string in runtime_strerror()
fast_develop_all_commits bbfc2e9 [origin/fast_develop_all_commits] [fix] incorrect error string in runtime_strerror()
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
fast_develop_all_commits_t 20d024b [origin/fast_develop_all_commits_t: gone] update print debug info
fast_t_xxw 77aa6d5 [origin/fast_t_xxw: gone] [fix] read devices with id greater than 255
fast_xxw_input_output_no32M 8b43189 [origin/fast_xxw_input_output_no32M: gone] [fix] no 32M limit for input/output in DDR
* fdac_xxw aa82f84 [origin/fdac_xxw] [feat] add ioctl to release process
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已经不存在了。