基本 git 分支管理命令

1. 查看本地分支

    git branch 。命令会列出所有分支,当前分支前面会标一个*号。 

2. 查看本地和远程所有分支

    git branch -a

3. 切换分支

    git checkout  xxx   。命令切换到xxx分支。

4. 创建本地分支

    git branch local_branch

5. 创建本地分支 并切换

    git checkout -b dev  。git checkout命令加上-b参数表示创建并切换到dev

6. 提交代码到本地仓库

    git add .  。

    git commit -a -m "description" 。把全部更改提交到本地库

7. 合并指定分支xxx到当前分支

    git merge xxx 。也就是直接把当前分支指针指向xxx的当前提交。

8. 拉远程分支remote_branch到本地,在本地起名为local_branch,并切换到本地的local_branch分支

    git checkout -b local_branch origin/remote_branch 。

   方法二:git fetch origin remote_branch:local_branch  获取远程分支,新建本地分支。

                 git checkout local_branch 切换到新建分支

9.  推送本地分支local_branch到远程分支 remote_branch并建立关联关系

     a.远程已有remote_branch分支并且已经关联本地分支local_branch且本地已经切换到local_branch

          git push

     b.远程已有remote_branch分支但未关联本地分支local_branch且本地已经切换到local_branch

         git push -u origin/remote_branch

     c.远程没有有remote_branch分支并,本地已经切换到local_branch

        git push origin local_branch:remote_branch

10. 删除本地分支local_branch ,不能在要删除的分支上,先切到其他分支,再删除

     git branch -d local_branch 

11. 删除远程分支remote_branch

     git push origin  :remote_branch

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

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

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

12.查看远程分支是否已经删除git branch -p

    通过git branch -a 仍然可以看到该分支,

    那么通过git remote show origin命令查看

12.查看版本号,回滚到指定的版本

    git log --pretty=oneline

    git reset --hard e3333333333333

    强制提交

   git push -f origin branch


-------------------------------------------

详细学习教程可参考

https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013743862006503a1c5bf5a783434581661a3cc2084efa000

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值