搭建公共的仓库
第一步:Ubuntu 安装 Git: apt-get install git
CentOS 安装 Git: yum install git
第二步:配置置 Git 用户信息:
git config --global user.name "随意输入" git config --global user.email "输入自己的邮箱地址"
第三步:
centos可以跳过
Ubuntu 安装 SSH: apt-get install ssh
第四步:
生成 SSH KEY: ssh-keygen -t rsa -C "输入自己的邮箱地址"
连按回车
第五步:
进入
root@localhost:~# cd /root/.ssh
root@localhost:~/.ssh# ls -a
其中的id_rsa 为私钥,id_rsa.pub 为公钥
然后vim id_rsa.pub查看公钥并且复制
第六步:
登录 GitHub,打开 Personal settings 页面,选择 SSH and GPG keys 选项
https://github.com/settings/keys
右上角new sshkey
然后输入你复制的公钥 Title随意写
第七步创建一个仓库
Repository name写个testnew(仓库名字为testnew)
创建完后找到这个
第八步 复制
git clone git@github.com:Leathersofa/testnew.git
然后cd testnew
vim a.txt//创建一个a.txt 并且在里面输入随意数字
git add a.txt//文件添加到暂存区
git commit -m "add a.txt"//注释到底做了啥
git push origin master //推送
搭建私有的仓库
第一步
我在home目录下搭建私有仓库 cd /home
搭建名字为siyou的仓库
git init --bare siyou.git
然后我在window下载了github
鼠标右键选择Git Bash here
git config --global user.name "随意输入" git config --global user.email "输入自己的邮箱地址"
ssh-keygen.exe -t rsa -C '输入自己的邮箱地址'
然后获取到的公钥 复制里面的内容 然后去linux服务器
cd /root/.ssh/
然后vim authorized_keys 黏贴你复制的公钥(相当于上面的第六步)
然后在windows输入
$ git clone root@120.79.149.235(这是我的阿里云服务器地址):/home/siyou.git 就行了
接下去像仓库推送你的东西跟上面步骤一样了
公有的仓库意思就是在github上创建一个仓库 这个别人可见
私有的仓库意思就是在你的linux服务器上创建一个仓库 这个自己可见
最后如果仓库更新了 你要及时更新 输入git pull就行了