git使用心得

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值