目录
一、下载及安装git程序
- 在git官网下载对应自己系统的git应用程序,官网:https://git-scm.com/download/win
- 双击下载的git.exe进行安装,安装路径可以自行更改,在其中一个选项中可以选择Use Git and optional Unix tools from the Command Prompt这个选项,也可以选择默认方式。
- 安装完成后,在桌面中点击右键出现Git GUI here和Git Bash Here,表示安装成功。
注:win+R,输入cmd,打开命令行窗口,输入git也可检查是否安装成功(需要更改2中选项)
二、git相关环境配置
注:两种方式 ①鼠标右击选择Git Bash Here ②cmd命令行窗口
1、在GitHub官网中注册一个GitHub的账号,官网地址:https://github.com/
2、为git配置用户名和密码,--global中存储了提交用户的name和email,手动设置可以使用如下指令
name配置:
git config --global user.name 注册GitHub的用户名
email配置:
git config --global user.email 注册GitHub使用的邮箱
3、检查配置是否正确,输入以下命令,出现user.name=注册GitHub的用户名 user.email=注册GitHub使用的邮箱
git config --list
4、利用git生成ssh协议,输入:
ssh-keygen -t rsa
三次回车之后就会生成.ssh文件夹,路径如图所示
5、在GitHub中建立连接,具体是访问 https://github.com/settings/ssh/new,title内容任起,key内容复制id_rsa.pub文件中的内容,可用记事本打开进行复制。
6、最后检验是否完成连接可以在Git Bash中输入:
ssh -T git@github.com
显示以下内容表示连接成功:
三、创建存储库
echo "# text" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:hu-thid/text.git
git push -u origin main
四、github上传大文件
注:先把 .gitattributes 文件push到GitHub远程仓库
1 安装Git LFS扩展
sudo apt install curl
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt install git-lfs
2 检验安装是否成功
git lfs install
3 track 大文件
git lfs track <large_file>
注:运行git lfs track <large_file>命令后生成 .gitattributes 文件,先将.gitattributes 文件push到GitHub远程仓库。
git add .gitattributes
git commit -m ''
git push origin main
4 按照正常顺序添加、提交、推送
git add <large_file>
git commit -m ''
git push origin main