zoukankan      html  css  js  c++  java
  • 代码版本管理工具-gitlab

    gitlab使用

    1.安装git

    [root@localhost ~]# yum install git -y

    2. git使用

      使用git命令行将本地仓库代码上传到github或gitlab远程仓库

        1)在本地创建了一个 renyongbin_01工程项目,现通过 命令行 将该项目上传到gitlab 远程仓库,具体操作流程如下:

          第1步:建立本地 git 仓库,cd 到你的本地项目根目录下,执行 git init 命令

            cd 本地工程根目录

            git init //这个目录就变成了git可以管理的仓库

            即  [root@localhost ~]# cd /data/renyongbin_01/          

               [root@localhost renyongbin_01]# git init
             Initialized empty Git repository in /data/renyongbin_01/.git/   

          第2步:将本地项目工作区的所有文件添加到暂存区。小数点 “.” ,意为添加文件夹下的所有文件;也可以将 “.” 换成具体的文件名,如果想添加项目中的指定文件,那就把 “.” 改为指定文件名即可

            a.先在本地创建一个测试文件:test1027_01.txt         

            [root@localhost renyongbin_01]# cat test1027_01.txt
            test1027 1446PM rybhaha

            b.将添test1027_01.txt文件添加到暂存区        

            [root@localhost renyongbin_01]# git add test1027_01.txt
            You have new mail in /var/spool/mail/root      

          第3步:将暂存区的test1027_01.txt文件提交到本地仓库      

          [root@localhost renyongbin_01]# git commit -m "test1027 1446PM ryb"
          [master (root-commit) a6d6c40] test1027 1446PM ryb
          1 file changed, 1 insertion(+)
          create mode 100644 test1027_01.txt
          You have new mail in /var/spool/mail/root     

          第4步:在gitlab 上创建新的repository,本文基于 gitlab 操作,github 类似。创建如下图所示:

          

     复制一下远程仓库的https地址:

          第5步:将本地代码仓库关联到 gitlab 上

            [root@localhost renyongbin_01]# git remote add origin http://192.168.56.115/root/rybtest.git

          第6步:将代码由本地仓库上传到 gitlab远程仓库,依次执行下列语句

          a.获取远程库与本地同步合并(如果远程库不为空必须做这一步,否则后面的提交会失败):       

    [root@localhost renyongbin_01]# git pull --rebase origin master    (注意:不加这句可能报错,原因是 gitlab 中的 README.md 文件不在本地仓库中 ,可以通过该命令进行代码合并)
    warning: no common commits
    remote: Counting objects: 3, done.
    remote: Total 3 (delta 0), reused 0 (delta 0)
    Unpacking objects: 100% (3/3), done.
    From http://192.168.56.115/root/rybtest
    * branch master -> FETCH_HEAD
    First, rewinding head to replay your work on top of it...
    Applying: test1027 1446PM ryb

          b.把当前分支 master 推送到远程,执行此命令后有可能会让输入用户名、密码:      

    [root@localhost renyongbin_01]# git push -u origin master
    Username for 'http://192.168.56.115': root
    Password for 'http://root@192.168.56.115':
    Counting objects: 4, done.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 315 bytes | 0 bytes/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To http://192.168.56.115/root/rybtest.git
    75bae03..14ffa9f master -> master
    Branch master set up to track remote branch master from origin.
    You have new mail in /var/spool/mail/root

    注意:git push -u origin master    执行完之后如果无错误就上传成功了,需要提示的是这里的 master 是 github 默认的分支。如果你本地的当前分支不是 master,就用git checkout master命令切换到master分支。如果你想用本地当前分支上传代码,则把第6步的命令里的 master 切换成你的当前分支名即可。至此操作OK,如下!

    你不向我走来,我便向你走去。
  • 相关阅读:
    Android 控件的学习
    Java并发编程
    Glide的学习之路
    插件化和热修复学习之路
    OkHttp的学习
    WMS的学习
    app一点一滴的学习
    进程启动学习
    View学习之解决滑动冲突
    应用学习
  • 原文地址:https://www.cnblogs.com/renyongbin/p/15427537.html
Copyright © 2011-2022 走看看