1、准备工作
git 下载地址:Git 安装过程一路next即可,注意路径即可
github注册地址:GitHub: Where the world builds software · GitHub
2、git有关命令
git add .
git commit -m "提交的信息"
git push origin master 将
git remote add 远程仓库名称(origin) 远程仓库地址
git diff # 比较提交前后文件的不同
git status # 有哪些文件变换,包括增加,改变,删除等
git merge otherbranch 把其他分支,合并到当前分支,并保留历史信息
git rebase 清除以前历史merge信息,保留最终结果
3、Git,Idea 上传代码到github
(1)git秘钥生成以及配置
#1 生成秘钥(已有将重复生成)
sh-keygen -t rsa -b 4096 -C "youremail@youremail.com",然后一直enter即可(也可以自己设置密钥文件名)生成两个文件为id_rsa.pub与id_rsa
文件位置C:\Users\tiger\.ssh (mac电脑位置 ~/Users/yourMacName/.ssh)
#2 复制公钥到github中:
公钥在id_rsa.pub中(以ssh-开头,以邮箱为结尾)
#3 Github 中,我的->Settings->SSH and GPG keys->New SSH keys,见3图
#4 ssh -T git@github.com 测试一下,看到成功授权即可,见4图
说明:
步骤3结果

image.png
步骤4结果

image.png
(2)用git命令上传本地仓库到github中(方式1)
cd要建仓库的文件夹内
git init(创建本地仓库)
git add --all(.)(添加所有文件)
git commit -m "first commit"
git remote add origin git@github.com:MiraclePandas/repository1.git(添加远程仓库origin,地址为git@github....,https方式类似)
git push -u origin master (其中-u表示新仓库是空的,当有第二次后就不用加了这参数了)
添加单个文件
echo "# repository1" >> README.md (创建READEM.md文件)
git add README.md (添加READEM.md文件)
git commit -m "second commit"
git push origin master
(3)idea方式上传到github(方式2)
1)、在preferences(mac) 或者window中找到->git->git安装路径->Test 提示成功

image.png
2)、github中 我的头像->Settings->Developer Settings -> Personal access tokens -> Generate new token 密码token仅仅显示一次,要复制下来

image.png
3) 将token填入下面即可

image.png
4)配置git的全局变量:
git config --global --list 查看全局的用户与邮箱配置
git config --local --list 查看本地的用户与邮箱配置
#说明:
# 比如这种情况 你想提交文件到githup用一个名字,提交到公司仓库上用另外一个名字
#可以这么操作
# 提交到公司我想让我的用户名与邮箱
git config --global user.name yourNameOfCompany
git config --global user.email yourNameOfCompany@xxx.com
#提交到github上你想用一个另一个名字与邮箱
# 本地的git仓库,或者idea 当前项目那个terminal路径下,注意:本地这个名字被改了,但是其他的仓库名称仍然用原来的提交名称
git config user.name yourName
git config user.email yourName@xxx.com