Git - 安装 & 配置

139 阅读1分钟

1、下载( 安装 )

http://git-scm.com/download

2、查看版本

git --version

3、配置用户信息

// 查看配置信息
git config --list

// 配置用户名和邮箱
git config --global user.name "mzy" git config --global user.email "....@qq.com"

4、配置 SSH

本地生成密钥对

// 1、进入主目录下的 ~/.ssh 目录
$ cd ~/.ssh   

// 2、生成公钥和秘钥
ssh-keygen -t rsa -C "mfrwyy@163.com"
ssh-keygen -t rsa -C "mengfanrong@shinemo.com"

// 3、查看生成的秘钥
$ ls  // 查看生成的文件
cat ~/.ssh/id_rsa.pub // 查看公钥,用来授权
cat ~/.ssh/id_rsa  // 查看密钥

// windows

添加公钥到远程仓库

// 配置github
1、登录github账户
2Settings 
3、左栏点击 SSH and GPG key
4、点击 New SSH key
5、复制公钥内容,粘贴进“Key”文本域内
6、title域,自己随便起个名字
7、点击 Add key
8、ssh -T git@github.comAttempts to ssh to github

5、当前仓库添加远程仓库地址

// 查看远程仓库地址
git remote -v


// 新增远端仓库地址
git remote add <name> <url> 
git remote add origin https://gitee.com/mzynet/111.git // 远程仓库别名为 "origin"
git remote add zhangsan https://gitee.com/mzynet/222.git // 远程仓库别名为 "zhangsan"


// 修改某个远程仓库地址
git remote set-url <name> <url>
git remote set-url origin https://gitee.com/mzynet/333.git


// 删除远程仓库
git remote remove <name>
git remote remove zhangsan