本文适用于个人机器快速配置Git,推送代码到远程仓库。多人以及团队协作,需要解决冲突。
1. Linux本地配置Git,并连接GitHub
安装git(Ubuntu18.04)
sudo apt-get update
sudo apt-get install git
配置用户名和密码,配置内容在~/.gitconfig文件中。
git config --global user.name "xxxxx"
git config --global user.email "xxxxx@qq.com"
git config --list
生成SSH Keys,复制id_rsa.pub文件中的公钥到GitHub或者Gitee。
ssh-keygen -t rsa -C "xxxxx@qq.com"
cat ~/.ssh/id_rsa.pub
测试是否连接成功。
ssh -T git@github.com
2. 克隆远程库到本地,拉取代码
ac@ac:~$ cd ~/workspace/
ac@ac:~/workspace$ git clone https://github.com/xxxxx/xxxxx.git
ac@ac:~/workspace$ ls
codeinterview Demo Test
此时,我们可以将项目导入到IDE中进行代码开发。每次推送会校验远程仓库账号和密码