git branch用法总结

简介:
git branch
   
    git branch 不带参数:列出本地已经存在的分支,并且在当前分支的前面加“*”号标记,例如:
   #git branch
* master
   newbranch

   git branch -r 列出远程分支,例如:
   #git branch -r
   m/master -> origin_apps/m1_2.3.4
   origin_apps/hardware/test
   origin_apps/m1
   origin_apps/m1_2.3.4
   origin_apps/master

   git branch -a 列出本地分支和远程分支,例如:
   #git branch -a
   * master
   newbranch
   remotes/m/master -> origin_apps/m1_2.3.4
   remotes/origin_apps/hardware/test
   remotes/origin_apps/m1
   remotes/origin_apps/m1_2.3.4
   remotes/origin_apps/master

   git branch 创建一个新的本地分支,需要注意,此处只是创建分支,不进行分支切换,例如:
   #git branch newbranch2
   #git branch
   * master
   newbranch
   newbranch2
   当前的分支依然是master,不进行切换。

   git branch -m | -M oldbranch newbranch 重命名分支,如果newbranch名字分支已经存在,则需要使用-M强制重命名,否则,使用-m进行重命名。

   git branch -d | -D branchname 删除branchname分支

   git branch -d -r branchname 删除远程branchname分支


例子:
git help branch中的一个例子:
   $ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
   $ cd my2.6
   $ git branch my2.6.14 v2.6.14   
   $ git checkout my2.6.14      

   第三行符合git branch <branchname> [<start-point>]的格式,即以v2.6.14为start-point,创建新的本地分支branchname。



本文转自莫水千流博客园博客,原文链接:http://www.cnblogs.com/zhoug2020/p/5917000.html,如需转载请自行联系原作者

相关文章
|
5月前
|
人工智能 数据可视化 开发工具
Git log 进阶用法(含格式化、以及数据过滤)
Git log 进阶用法(含格式化、以及数据过滤)
|
12月前
|
开发工具 git
【Git用法】git常用命令
【Git用法】git常用命令
55 0
|
12月前
|
编译器 开发工具 git
【Git异常】You are in ‘detached HEAD‘ state, which means that you‘re not on any branch Checkout a branch
【Git异常】You are in ‘detached HEAD‘ state, which means that you‘re not on any branch Checkout a branch
164 0
|
4天前
|
安全 网络安全 开发工具
深入探索Git:全面解析Git的用法与最佳实践
深入探索Git:全面解析Git的用法与最佳实践
16 2
|
2月前
|
开发工具 git
Git 中的 fork、branch 和 clone
【8月更文挑战第27天】
97 5
|
2月前
|
Java 开发工具 Android开发
Android Studio利用Build.gradle导入Git commit ID、Git Branch、User等版本信息
本文介绍了在Android Studio项目中通过修改`build.gradle`脚本来自动获取并添加Git的commit ID、branch名称和用户信息到BuildConfig类中,从而实现在编译时将这些版本信息加入到APK中的方法。
44 0
|
5月前
|
开发工具 git
git branch (branchname)
git branch (branchname) 是 Git 中创建和管理分支的一种命令。通过这个命令,你可以根据指定的分支名创建一个新的分支,或者跳转到已经存在的分支上。branchname 参数是可选的,如果不指定,则默认创建或切换到主分支(master 或 main)。
121 8
|
4月前
|
开发工具 git
idea的git reset current branch to here操作详解
idea的git reset current branch to here操作详解
296 1
|
5月前
|
开发工具 git
避免git产生Merge branch 'foo' into 'bar'提交
避免git产生Merge branch 'foo' into 'bar'提交
90 3
|
5月前
|
存储 数据可视化 前端开发
20个常用的 Git 指令用法
20个常用的 Git 指令用法
125 1