跳到主要内容

Git config

优先级 local > global > system, 如果 local 没设置,就会用 global 的信息。 local作用于当前仓库,global作用于当前用户。

Command


git config --global user.name "yourname"
git config --global user.email "your@email.com"
git config --global --unset user.name
git config --global --unset user.email


git merge --squash dev # 合并dev到当前分支,将所有提交合并为单一提交
git add .
git commit -m "feature" --date="2025-8-01T12:35:00+0800"
git push




######################创建一个空的分支
git init -b main
git remote add origin xxxxxxxxxxxxxxxxxxx
git checkout --orphan main
git commit --allow-empty -m "Initial commit on empty main branch"
git push --set-upstream origin main
git checkout -b snapshot
git push --set-upstream origin snapshot




git config --global init.defaultBranch main

## 缓存配置
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=3600'

## 存储凭据,不安全,一般不推荐
#git config --global credential.helper store
凭证会保存在 ~/.git-credentials 文件中

配置密钥链凭证存储
#macOS     git config --global credential.helper osxkeychain
#windows   git config --global credential.helper manager-core