为了能在任意 Git 项目上协作,你需要知道如何管理自己的远程仓库。 远程仓库是指托管在因特网或其他网络中的你的项目的版本库。
1.在www.github.com官网上注册一个账号,创建自己的仓库,只能是公有的,因为在github上创建私人是需要收费的
2.创建一个项目demo
因为我们要以ssh方式上传代码或者获取代码,所以我们要将获取shell和远端之间的密钥
[root@server1 ~]# cd .ssh/
[root@server1 .ssh]# ls
authorized_keys id_rsa id_rsa.pub known_hosts
[root@server1 .ssh]# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCY9In0yAU3D2G/iVZLfbLB/w/CviImhDNrterlPtYK1U4kFYIFMSaRc1LPD0GTZ6Z6MrH09szKr06MuOB8I3HbnqBAmDxIjPtdBqVXdFBficuchlGivdVbjIuBxZtK3qGcmcQeOS/v/iTC2ghMvHAzo0+BWyZ/cGiPT9CZiYZ4YR6NCxP84kvh7/L4gHgO3j6/khki7/UVd0DjHih8/8jUT7yjCaM2MomDq49+9HuSRbXMSbMplvT/rTvf/qgOfeb72B75hepH7HpTmhoG2TAOXcvAwtI0qMJ0ztal7c+oJ0mWoYIyfLjTwazptOeWuPA8Zv9OoUV+hxdId9asH5Xz root@server1
点击右上角用户—>setting—>ssh加密方式—->将在shell中获得的ssh密钥复制下来
4.推送本地库到远程仓库
[root@server1 ~]# cd demo/
[root@server1 demo]#
[root@server1 demo]# git remote add origin git@github.com:xibei316/demo.git
[root@server1 demo]# git remote -v
origin git@github.com:xibei316/demo.git (fetch)
origin git@github.com:xibei316/demo.git (push)
[root@server1 demo]# git push -u origin master
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
Counting objects: 7, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (7/7), 491 bytes | 0 bytes/s, done.
Total 7 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To git@github.com:xibei316/demo.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
网页上本来没有文件
刷新后就会出现demo目录下的file1文件
在目录中新添加一个文件,再次上传刷新
[root@server1 demo]# echo hello > westos
[root@server1 demo]# ls
file1 westos
[root@server1 demo]# git add westos
[root@server1 demo]# git commit -m "add westos"
[master 0ea5e20] add westos
1 file changed, 1 insertion(+)
create mode 100644 westos
[root@server1 demo]# git push -u origin master
Warning: Permanently added the RSA host key for IP address '13.229.188.59' to the list of known hosts.
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 267 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:xibei316/demo.git
0bd517d..0ea5e20 master -> master
Branch master set up to track remote branch master from origin.
5.克隆远程仓库到本地
首先新建一个库git(注意选项)
查看库里的文件
克隆
[root@server1 ~]# git clone git@github.com:xibei316/git.git
Cloning into 'git'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
[root@server1 ~]# ls
2018 ansible demo git
[root@server1 ~]# cd git/
[root@server1 git]# ls
README.md
[root@server1 git]# cat README.md
# git[root@server1 git]#