Git(4)分支操作

1、创建分支

git branch <newBranchName>

2、切换分支

git checkout <branchName>

        分支切换会改变工作目录中的文件。Git会自动添加、删除、修改文件以确保此时你的工作目录和这个分支最后一次提交时的样子一模一样。

3、创建分支并切换

git checkout –b <newBranchName>

4、合并分支的步骤(例如合并到主分支)

(1)切换回主分支

git checkout master

(2)然后合并其他分支到主分支中

git merge <otherBranchName>

(3)最后删除被合并了的分支

git branch –d <otherBranchBame>

5、查看分支

(1)查看当前所有分支

git branch (-v)

(2)查看哪些分支已经合并到当前所在分支

git branch –merged

(3)查看哪些分支未合并到当前所在分支

git branch –no-merged

6、推送到远程分支

(1)推送本地分支1到远程仓库上的分支1

git push <remoteName> <branch1>

(2)推送本地分支1到远程仓库上的分支2

git push <remoteName> <branch1>:<branch2>

7、跟踪远程分支

(1)创建本地分支branch1并跟踪远程分支<branchName>

git checkout –b <branch1> <remoteName>/<branchName>

(2)设置已有的本地分支跟踪一个刚刚拉取的远程分支

git branch –u <remoteName>/<branchName>

8、拉取远程分支

(1)推荐使用fetch拉取一个远程分支,然后再将该分支合并到某个已经存在的本地分支中。

 a)先创建一个本地分支

git checkout –b <localBranch>

 b)拉取远程分支

git fetch <remote> <branch>

c)合并到本地分支

git merge <remote> <branch>

(2)使用pull拉取一个已经被跟踪的远程分支

 a)先创建一个本地分支并跟踪到欲拉取的远程分支

git checkout –b <branch1> <remote>/<branch2>

 b)再拉取远程分支

git pull <branch2>

9、跟踪远程分支

(1)当前分支跟踪一个远程的分支

git checkout --track <remoteName>/<branchName>

(2)设置已有的本地分支跟踪一个刚刚拉取下来的远程分支,或者想要修改正在跟踪的上游分支:

git branch -u/--set-upstream-to <remoteName>/<branchName>

10、删除远程分支

git push <remote> --delete <branch>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值