GIT 仓库搭建

2021/06/15 Git 共 808 字,约 3 分钟

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_rsaid_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 

文档信息

Search

    Table of Contents