别名

git config --global alias.ck checkout

git config --global alias.br branch

git config --global alias.ct commit

提交流程

git add <file/dir>  # 工作区 -> 暂存区
git commit -m "some info" # 暂存区 -> 本地仓库
git push # 本地仓库 -> 远程仓库

创建分支

git checkout -b <branch name>

更新.gitignore

git rm -r --cached . // 删除本地缓存
git add . // 添加要提交的文件
git commit -m 'update .gitignore' // 更新本地的缓存

拉取远端分支

git pull <branch name> origin/<branch name>

合并代码-拒绝合并不相关的历史

合并代码时出现refusing to merge unrelated histories报错

merge后加入--allow-unrelated-histories即可

git merge <branch name> --allow-unrelated-histories

git pull命令

git pull的命令是由两个命令组成,git fetch和git merge

查看服务器名称

git remote -v

设置代理

问题:不能连接到github.com

如果使用vpn代理需要设置代理

git config --global http.proxy 127.0.0.1:10809
git config --global https.proxy 127.0.0.1:10809

查看git配置

git config --global -l

LFS 大文件存储

git lfs可以用于上传大文件

上传

git init #创建本地仓库环境
git lfs install #安装大文件上传应用
git lfs track * #追踪要上传的大文件,*表示路径下的所有文件
git add .gitattributes #添加先上传的属性文件(要先上传属性文件,不然有可能失败)
git commit -m "pre" #添加属性文件上传的说明
git remote add origin https://github.com/Youpeng-Zhang/MOP.git #建立本地和Github仓库的链接
git push origin master #上传属性文件
git add * #添加要上传的大文件,*表示路径下的所有文件
git commit -m "Git LFS commit" #添加大文件上传的说明
git push origin master #上传大文件

下载

git lfs clone git@bitbucket.org:tpettersen/Atlasteroids.git # 下载大文件
git lfs fetch # 中断后可根据之前的进度进行下载