为了能在任意 Git 项目上协作,你需要知道如何管理自己的远程仓库。 远程仓库是指托管在因特网或其他网络中的你的项目的版本库。
搭建github远程仓库
1.首先在www.github.com官网上注册一个账号,创建自己的仓库,只能是公有的,因为在github上创建私人是需要收费的
2.创建一个项目demo
3.以ssh方式上传代码或者获取代码,所以我们要将获取shell和远端之间的密钥
查看生成的公钥,然后将其写入github仓库的验证里
点击右上角用户—>setting—>ssh加密方式—->将在shell中获得的ssh密钥复制下来
4.推送本地仓库到远程仓库
[root@server1 ~]# cd demo/
[root@server1 demo]# git remote add origin git@github.com:xuptpipi/demo.git
[root@server1 demo]# git remote -v ##可以查看远程仓库
origin git@github.com:xuptpipi/demo.git (fetch)
origin git@github.com:xuptpipi/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: 6, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 419 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To git@github.com:xuptpipi/demo.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
在github上查看
我们新建一个文件,再次上传
[root@server1 demo]# echo 'hello world' > test
[root@server1 demo]# ls
file1 test
[root@server1 demo]# git add test
[root@server1 demo]# git commit -m "add test"
[master aeedf99] add test
1 file changed, 1 insertion(+)
create mode 100644 test
[root@server1 demo]# git push -u origin master
5.克隆远程仓库到本地
- 首先新建一个库