Git安装配置(ubuntu、windows)

ubuntu安装配置

Git配置

  1. 开通gitlab帐号
  2. 配置hosts文件:打开hosts文件,添加配置 “xxx.xx.x.xx(ip) gitlab”
sudo gedit /etc/hosts
  1. 生成SSH密令:密令默认存放路径 “~/.ssh/”,回车跳过密码设置 -> 完成)
ssh-keygen -t rsa -C "gitlab邮箱等帐号标识"
  1. 配置SSH密令:查看并复制完整密钥 -> 浏览器访问 gitlab -> profile settings -> SSH Keys -> add SSH key -> 粘贴密钥到 KEY 中 -> Add key -> 完成
cat ~/.ssh/id_rsa.pub 
  1. 拷贝项目到本地:如果失败,重启电脑
git clone git@xxxxxxxx
  1. 添加Git配置
git config --global user.email "gitlab邮箱等帐号标识"
  1. 添加Git配置
git config --global user.name "gitlab帐号姓名"
  1. 提交&拉取文件
git pull  -->  git add . --> git commit -am "*更新内容*" --> git pull --> git push

windows安装配置

安装git

下载地址 http://git-scm.com/download/win
直接默认安装即可

配置电脑hosts

c://windows/System32/driver/etc 的hosts文件
右键“属性”-“安全”-“编辑”下方更改为全部控制。应用后使用记事本打开hosts文件,添加如下内容

172.16.0.100 gitlab

生成ssh key

  1. 打开Git Gui 点击Help,打开show ssh key
  2. 点击generate key生成一个ssh key

重新生成ssh key

使用Git Bash生成新的ssh key。

# 保证当前路径在默认路径下
cd ~  
# 建议填写自己真实有效的邮箱地址
ssh-keygen -t rsa -C "[email protected]" 

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxxx_000/.ssh/id_rsa):   #不填直接回车
Enter passphrase (empty for no passphrase):   # 输入密码(可以为空)
Enter same passphrase again:   # 再次确认密码(可以为空)
Your identification has been saved in /c/Users/xxxx_000/.ssh/id_rsa.   # 生成的密钥
Your public key has been saved in /c/Users/xxxx_000/.ssh/id_rsa.pub.  # 生成的公钥
The key fingerprint is:
e3:51:33:xx:xx:xx:xx:xxx:61:28:83:e2:81 [email protected]

配置git

复制完整密钥 -> 浏览器访问 gitlab -> profile settings -> SSH Keys -> add SSH key -> 粘贴密钥到 KEY 中 -> Add key -> 完成

发布了77 篇原创文章 · 获赞 19 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/baidu_36943075/article/details/100150886