1. 克隆远程仓库
git clone https://git.XXX.XXXX/XXXX.git
// 克隆某个分支
git clone -b 分支名 https://git.XXX.XXXX/XXXX.git
2. 分支操作
// 1.查看分支信息
git branch
// 2.同步远程分支信息
git fetch
// 3.查看本地关联的远端分支
git branch -vv
// 4.检出分支
git checkout [branch_name]
// 5.在当前分支的基础上新建本地分支
git checkout -b [branch_name]
// 6.忽略本地代码更改
git checkout -f
// 7.删除本地分支
git branch -D [branch_name]
// 8.删除远端分支
git push origin --delete [branch_name]
3. 提交代码流程 -- merge
主分支加保护,阻止成员直接push,在gitLab提交merge请求时需要审核
// 当前在本地开发分支上
git add .
// 查看文件修改状态
git status
git commit -m 'Fix/Feat: XXXXXX'
// 当此分支有关联远端分支时
git pull
// rebase远端主分支(当前线上分支)
git rebase origin/[master]
// ***解决冲突*** //
git add .
git commit -m 'Fix/Feat: XXXXXX'
git rebase --continue
// rebase成功后
git push
// 当远端无关联分支时 使用
git push --set-upstream origin [当前分支名]
4. 提交代码流程 -- push
直接使用push操作,使分支情况更加清晰,每次从主分支拉取开发分支,用过即删
// 检出主分支
git checkout [master]
// 将本地主分支与远程代码同步加合并
git pull --rebase
// 在主分支基础上建立开发分支
git checkout -b [branch_feature]
// *** 开发 *** //
git add .
git commit -m 'Fix/Feat: XXXXXX'
git rebase origin/[master]
// 切换至主分支
git checkout [master]
// 同步远程代码
git pull --rebase
// rebase开发分支
git rebase [branch_feature]
// *** 解决冲突 *** //
git add .
git rebase --continue
git push
// 若此时push失败,表示有其他人在此前push过,此时再次合并即可
git pull --rebase
git add .
git rebase --continue
git push
5. 配置git信息
// 查看当前信息
git config --global user.name
git config --global user.email
// 配置信息
git config --global user.name ’name‘
git config --global user.email 'email@XXX.com'
6. 忽略SSL证书验证
使用yarn安装依赖时的报错信息
忽略SSL验证
// 可能发生在clone时
git config --global http.sslVerify "false"
// yarn 安装依赖报错时
yarn config set "strict-ssl" false
// MAC关闭验证
export GIT_SSL_NO_VERIFY="true"
7.使用暂存区
使用场景:在a分支更改的代码想要移到b分支上
// current branch branch-a
git stash save "message"
// 切分支
git checkout branch-b
// 取出暂存区代码
git stash pop