git分支操作


  1. 创建分支

    $ git branch demo

    创建并切换分支 $ git checkout --orphan demo , git checkout -b demo

  2. 查看分支

    $ git branch
      demo
    * master
  3. 切换分支

    $ git checkout demo
    切换到分支 'demo'
  4. 删除分支

    example  ‹demo› $ git branch -d demo
    error: 无法删除您当前所在的分支 'demo'。
    example  ‹demo› $ git checkout master                                                     1 ↵
    切换到分支 'master'
    您的分支与上游分支 'origin/master' 一致。
    example  ‹master› $ git branch -d demo
    已删除分支 demo(曾为 fe1db33)。

    如果要同时删除数据, 则使用 git branch -D demo

  1. 删除文件夹

    $ git rm demo/ -r -f
    rm 'demo/index.html'
    rm 'demo/static/css/app.f97545042cb01edc9684b0303015c3b4.css'

    删除单个文件使用 git rm demo/index.html

  2. 提交分支

    $ git push origin demo
    Username for 'https://github.com': itaken
    Password for 'https://itaken@github.com':
    对象计数中: 23, 完成.
    Delta compression using up to 4 threads.
    压缩对象中: 100% (23/23), 完成.
    写入对象中: 100% (23/23), 1.27 MiB | 334.00 KiB/s, 完成.
    Total 23 (delta 1), reused 0 (delta 0)
    remote: Resolving deltas: 100% (1/1), done.
    To https://github.com/itaken/vue-example.git
     * [new branch]      demo -> demo
  3. 查看远程分支

    $ git ls-remote                    
    From https://github.com/itaken/vue-example.git
    5b93b0e89d133f34e3424bc745ee6488f9e2edxx    HEAD
    5b93b0e89d133f34e3424bc745ee6488f9e2edxx    refs/heads/master
    9c1b7e652ebf31c335d54928042f8d8a702ec0xx    refs/heads/demo
  4. 删除远程分支

    $ git push origin --delete demo
    Username for 'https://github.com': itaken
    Password for 'https://itaken@github.com':
    To https://github.com/itaken/vue-example.git
     - [deleted]         demo

参考文档


Author: Itaken
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Itaken !
  TOC目录