git config
查看配置
全局
1 2 3
| cat ~/.gitconfig git config --global user.name "username" git config --global user.email "email"
|
github令牌
2021年8月13号之后,github已经不让直接使用账号名密码来登录了,必须使用personal access token(个人访问令牌)
- 明文的密码很容易被泄露,如果换成有时限的token,即使泄露了影响也会非常有限。
- 可以为同一个github账号根据不同的使用途径,生成不同的token,并且随时都可以控制token的有效状态和不同token代表的权限。最大限度的保证账号的安全性。
- 生成的token可随时撤销,并且令牌的随机性更高,不容易被暴力破解。
我的账号->settings->Developer settings->Personal access tokens->Generate new token->(pc名字,粘贴key)->(Note:哪台电脑,有效期(Expiration)选90天,Select scopes选repo)
1 2 3
| $ git clone https://github.com/username/repo.git Username: your_username Password: your_token
|
ssh访问github
1 2 3 4
| ssh-keygen -t rsa -C "your email"
cat ~/.ssh/id_rsa.pub
|
我的账号->settings->SSH and GPG keys->New SSH key->(pc名字,粘贴key)
1 2 3
| ssh -T git@github.com
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.
|
局部(项目内的)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| cd projectdir/ cat .git/config git config user.name "username" git config user.email "email" cat .git/config
git config credential.helper cache
git config credential.helper 'cache --timeout=3600'
git config credential.helper store
git config credential.helper 'store --file /data/git/.git-credentials' cat .git/config
|
记住或取消密码记录
1 2 3
| (repository_home)/.git/config ~/.gitconfig /etc/gitconfig
|
1 2 3 4 5 6 7 8 9
| git config --set credential.helper 'cache --timeout=600' git config --global --set credential.helper 'cache --timeout=600' git config --system --set credential.helper 'cache --timeout=600'
git config --unset-all credential.helper git config --global --unset-all credential.helper git config --system --unset-all credential.helper
|
本地origin分支与远程不同步
1 2
| git remote show origin git remote prune origin
|
windows删除git记录
- 进入控制面板
- 选择用户账户
- 选择管理你的凭据
- 选择Windows凭据
- 选择git保存的用户信息
- 选择编辑或者进行删除操作
git查看各分支之间关系
1
| git log --graph --decorate --oneline --simplify-by-decoration --all
|
git status
中文乱码
1
| git config --global core.quotepath false
|