美文网首页
git常用操作

git常用操作

作者: idioitcbear | 来源:发表于2017-05-03 15:01 被阅读10次
    1. 更换远程分支

      • 先删除远程分支:
        git remote rm origin
      • 再添加远程分支:
        git remote add origin <origin_url>
    2. 新建、删除本地分支,以及删除远程分支

      • 新建本地分支
        git branch <new_branch_name>
      • 删除本地分支
        git branch -d <local_branch_name>
      • 删除远程分支
        git push origin --delete <remote_branch_name>
    3. 获取远程分支

      • 不重新命名
        git checkout <remote_branch_name>
      • 重新命名
        git checkout -b <local_branch_name> <remote_branch_name>
    4. git提交,及提交到远程分支
      git push origin <remote_branch_name>:<local_branch_name>

    5. 初始化git配置

      • 配置用户名,邮箱
        git config --global user.name <user_name>
        git config --global user.email <user_email>
      • 配置SSH
        • 生成ssh-key
              $ ssh-keygen -t rsa -C "idioticmadman@qq.com"
              Generating public/private rsa key pair.
              Enter file in which to save the key (/c/Users/robert/.ssh/id_rsa):
              Created directory '/c/Users/robert/.ssh'.
              Enter passphrase (empty for no passphrase):
              Enter same passphrase again:
              Your identification has been saved in /c/Users/robert/.ssh/id_rsa.
              Your public key has been saved in /c/Users/robert/.ssh/id_rsa.pub.
              The key fingerprint is:
              SHA256:UNSglMH1hfsrjrMI3tX8/tKHE/WOoTeLtoENs9VHwok idioticmadman@qq.com
              The key's randomart image is:
              +---[RSA 2048]----+
              |     .o==o ..    |
              |     .oo .o. o . |
              |      o   ..E + .|
              |       .  .  . o.|
              |        S o.. ..o|
              |         o B. o..|
              |    .   . = o+ * |
              |   . o o....=oB o|
              |    . o o+.+==o= |
              +----[SHA256]-----+
          
        • 把公钥添加到git服务器
    6. 配置多Git服务器
      在.ssh文件夹下新建config文件


      config.png

      config文件:

         # gitlab
           Host 192.168.10.52
           HostName 192.168.10.52
           PreferredAuthentications publickey
           IdentityFile ~/.ssh/funtsui_rsa 
        # github
           Host github.com
           HostName github.com 
           PreferredAuthentications publickey
           IdentityFile ~/.ssh/id_rsa 
      
    7. 配置submodule
      添加git的子仓库
      git submodule add <repository addr> <directory>
      初始化子仓库
      git submodule init
      更新子仓库
      git submodule update

    8. tag相关操作
      git tag <name> -m <message> 新增tag
      git tag -d <name> 删除tag
      git push origin <tag_name> 上传tag到远端
      git push origin :refs/tags/<tag_name> 删除远端tag

    相关文章

      网友评论

          本文标题:git常用操作

          本文链接:https://www.haomeiwen.com/subject/fcrzwttx.html