gitlab上传公钥和项目代码
admin
2023-03-01 11:02:51
0

gitlab上传项目需要ssh公钥免交互,本文介绍gitlab设置公钥和上传项目的操作。

一、创建秘钥对

[root@localhost ~]# ssh-keygen -t rsa #一路回车即可
gitlab上传公钥和项目代码
二、上传秘钥

[root@localhost ~]# cat ~/.ssh/id_rsa.pub #查看公钥
gitlab上传公钥和项目代码
三、上传本地代码

1、要先设置用户和邮箱

[root@localhost opt]# git config --global user.name "root"

[root@localhost opt]# git config --global user.email "w135xxxxx@qq.com"

[root@localhost opt]# git config --list

user.name=root

user.email=w135xxxx@qq.com

2、创建一个本地代码仓库

[root@localhost opt]# mkdir push_code

[root@localhost opt]# cd push_code/

3、初始化该仓库

[root@localhost push_code]# git init

初始化空的 Git 版本库于 /opt/pull_code/.git/

[root@localhost push_code]# echo "this is test push code" > push.txt

[root@localhost push_code]# ls

pull.txt

4、获取分支

#这个分支信息,可以在web界面clon里看到

[root@localhost push_code]# git remote add origin http://192.168.0.8:81/test/hellow.git

5、刷新远程仓库分支

[root@localhost push_code]# git fetch origin --prune

#获取所有远程分支

#现在处于master分支

[root@localhost push_code]# git branch -a

0a

  • master

    remotes/origin/devops

    remotes/origin/master

6、提交代码

#提交文件到本地仓库

[root@localhost push_code]# git add push.txt #添加文件

[root@localhost push_code]# git commit -m "this is test push" #添加说明

[root@localhost push_code]# git push origin master #推送代码至master分支

#小坑

[root@localhost push_code]# git push origin master

Username for 'http://192.168.0.8:81': root

Password for 'http://root@192.168.0.8:81':

To http://192.168.0.8:81/test/hellow.git

! [rejected] master -> master (non-fast-forward)

error: 无法推送一些引用到 'http://192.168.0.8:81/test/hellow.git'

提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。

提示:再次推送前,先与远程变更合并(如 'git pull')。详见

提示:'git push --help' 中的 'Note about fast-forwards' 小节。

#解决:重新拉取远程代码仓库信息,与远程仓库代码信息保持一致

[root@localhost push_code]# git pull http://192.168.0.8:81/test/hellow.git

Username for 'http://192.168.0.8:81': root

Password for 'http://root@192.168.0.8:81':

来自 http://192.168.0.8:81/test/hellow

  • branch HEAD -> FETCH_HEAD

已经是最新的!

7、切换分支

[root@localhost push_code]# git checkout devops

分支 devops 设置为跟踪来自 origin 的远程分支 devops。

切换到一个新分支 'devops'

[root@localhost push_code]# git branch -a

  • devops

    master

    remotes/origin/devops

    remotes/origin/master

其他分支上传代码方式相同重复步骤6即可

8、拉取指定分支代码

git clone -b devops http://192.168.0.8:81/test/hellow.git #-b指定拉取分支的代码

9、创建分支

git branch slave 创建slave分支

相关内容

热门资讯

玩家最新攻略“阳光巴厘岛.有没... 家人们!今天小编来为大家解答阳光巴厘岛透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪里买...
今日重大通报“大庆划水麻将.怎... 家人们!今天小编来为大家解答大庆划水麻将透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里...
玩家攻略科普“欢乐龙城9.究竟... 您好:欢乐龙城9这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9752949】很多玩家在这款游...
终于明白“青松游戏.真的有挂吗... 您好:青松游戏这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款游戏...
【第一资讯】“火神牛牛.怎么开... 有 亲,根据资深记者爆料火神牛牛是可以开挂的,确实有挂(咨询软件无需打开...
今日重大消息“大庆划水麻将.有... 网上科普关于“大庆划水麻将有没有挂”话题很是火热,小编也是针对大庆划水麻将作*弊开挂的方法以及开挂对...
今日重大通报“同城跑胡子.到底... 网上科普关于“同城跑胡子有没有挂”话题很是火热,小编也是针对同城跑胡子作*弊开挂的方法以及开挂对应的...
【第一消息】“灯塔麻将.辅助开... 家人们!今天小编来为大家解答灯塔麻将透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪里买很...
【第一消息】“沧海麻将.到底是... 网上科普关于“沧海麻将有没有挂”话题很是火热,小编也是针对沧海麻将作*弊开挂的方法以及开挂对应的知识...
京东:近期有不法分子冒名邮寄虚... 【大河财立方消息】 12月22日,京东发言人微博发文称,近期,发现有不法分子冒充京东向用户邮寄低价值...