Git远程仓库—码云gitee
1.git远程仓库简介
每次提交代码都是提交到本地仓库,我们现在将本地仓库的代码推送至远程仓库,供所有人下载
远程仓库:一个远程仓库对应一个本地仓库,不会混乱
2.使用gitee代码仓库
访问 https://gitee.com/
2.1新建一个仓库
点击+号---新建仓库
2.2配置git ssh免密码登录
由于远程仓库需要设置密码,因此我们采用ssh免密登录的方式 1)git服务器生成公私钥 [root@192 ~]# ssh-keygen [root@192 ~]# cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7tU/y3Pz5qJeJDhkNHj93Ysuikr3+e7mPikKKJp9vQ5OWogl26nKKxusq++8XTV2rmx0NxpVVaVPy5fBiNMtgZUPvYKpq/D/bXVRNVZ7cEHHkIVwdE8tQMeIUdNS32q91nzo9TerCmZLtcolPDwhhdbqlBLA4ihr6YPDSJDxLjPBArwhOF8NGjs63WGj2zyYBd8ldm97XNIZcU9Q0TfpkArN4Br9lRPKsLssCxsm0YzuSEXsdYBvZv03fat7J6zZeMR2w45j0jIu4b7bhK+KB+XfeuGQ+O2uYIOHrkYDzsj8eOXD+uXD61JyYHQSepvax/244pG3wgSJz+/DYolbp root@192.168.81.210 2)在gitee上添加公钥 点击头像--设置---ssh公钥---填写内容---确定
2.3.配置本地仓库连接远程仓库
[root@192 ~]# cd /data_git/ 1)添加gitee远程仓库 [root@192 data_git]# git remote add origin git@gitee.com:jiang_xiao_long/git_test.git 2)将本地master分支推送到远程仓库的master分支,-u表示远程仓库用户 [root@192 data_git]# git push -u origin master The authenticity of host 'gitee.com (212.64.62.183)' can't be established. ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc. ECDSA key fingerprint is MD5:27:e5:d3:f7:2a:9e:eb:6c:93:cd:1f:c1:47:a3:54:b1. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'gitee.com,212.64.62.183' (ECDSA) to the list of known hosts. Counting objects: 30, done. Compressing objects: 100% (23/23), done. Writing objects: 100% (30/30), 2.30 KiB | 0 bytes/s, done. Total 30 (delta 9), reused 0 (delta 0) remote: Powered by GITEE.COM [GNK-5.0] To git@gitee.com:jiang_xiao_long/git_test.git * [new branch] master -> master 分支 master 设置为跟踪来自 origin 的远程分支 master。
2.4.将bug分支推送至远程仓库
[root@192 data_git]# git branch bug * master [root@192 data_git]# git checkout bug 切换到分支 'bug' [root@192 data_git]# git push -u origin bug Total 0 (delta 0), reused 0 (delta 0) remote: Powered by GITEE.COM [GNK-5.0] remote: Create a pull request for 'bug' on Gitee by visiting: remote: https://gitee.com/jiang_xiao_long/git_test/pull/new/jiang_xiao_long:bug...jiang_xiao_long:master To git@gitee.com:jiang_xiao_long/git_test.git * [new branch] bug -> bug 分支 bug 设置为跟踪来自 origin 的远程分支 bug。
2.5.远程仓库实操
一般公司新来的开发人员是没有远程仓库的代码,因此我们一般先将仓库所有代码克隆一份到本地,然后让新员工进行改代码,提交—上传到远程仓库
注意第一次获取仓库代码时必须使用克隆,只将master的代码克隆到本地
克隆地址从下图获取
1)先将仓库镜像到本地 [root@192 data_git]# cd /opt/ [root@192 opt]# git clone git@gitee.com:jiang_xiao_long/git_test.git [root@192 opt]# cd git_test/ 2)修改file1文件并提交 [root@192 git_test]# cat file1 jiangxl jiangxl linux [root@192 git_test]# git add . [root@192 git_test]# git commit -m "第一次修改" [master 754e625] 第一次修改 1 file changed, 2 insertions(+), 6 deletions(-) 3)推送 [root@192 git_test]# git push -u origin master Counting objects: 5, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 295 bytes | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) remote: Powered by GITEE.COM [GNK-5.0] To git@gitee.com:jiang_xiao_long/git_test.git e7821a1..754e625 master -> master 分支 master 设置为跟踪来自 origin 的远程分支 master。 4)master去拉取代码 [root@192 data_git]# git pull -u origin master remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. 来自 gitee.com:jiang_xiao_long/git_test * branch master -> FETCH_HEAD 更新 e7821a1..754e625 Fast-forward file1 | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) [root@192 data_git]# cat file1 jiangxl jiangxl linux