Git 仓库搭建
参考:
下载 GitBash
使用国内镜像下载 GitBash for windows.
生成 SSH Key 并保存到服务器
桌面右键打开 gitbash
# 配置gitconfig
git config --global user.name "your name"
git config --global user.email "your@email.com"
# 生成ssh密钥
ssh-keygen -C "your@email.com"
# (按回车)
完成以上步骤后C:\Users\userName\.ssh
目录下有id_rsa
和id_rsa.pub
两个文件, 其中.pub
为公钥, 将其保存到服务器中.
# 将公钥追加到服务器authorized_keys文件中实现免密效果
cat C:\Users\userName\.ssh\id_rsa.pub >> git@<ip>:/home/git/.ssh/authorized_keys
# 或者使用这条命令
ssh git@服务器公网IP地址 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub
Clone 服务器代码
# 在文件夹路径下右键打开gitBash, 将代码拉取到当前目录.
git clone git@<ip>:/home/git/repository/mes.git
# 输入密码如 git
代码同步
# 同步本地分支代码和远程分支, 拉取远程代码到本地
git pull
# 查询修改
git status .
# 提交代码
git add .
git commit -m "本次修改的说明"
git push origin HEAD
文档信息
- 本文作者:正义的伙伴
- 本文链接:https://ableasd.github.io/2021/06/15/git%E4%BB%93%E5%BA%93%E6%90%AD%E5%BB%BA/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)