Git配置信息相关命令

查看git所有配置项

$ git config -l
or
$ git config --list

全局配置用户名邮箱

$ git config --global user.name "young"
$ git config --global user.email "young@163.com"

根据项目配置:

  • 切换到项目目录下,配置用户名和密码:
$ git config user.name "young"
$ git config user.email "young@163.com"
  • 配置信息的存储位置
对应的本地仓库的.git文件中的config文件
在当前项目目录下使用 cat .git/config,就可以看到配置文件内容
$ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[remote "origin"]
        url = https://github.com/***/***.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

git config解析

user.email=leo@xxx.com
user.name=leo
core.ignorecase=false            # 不许忽略文件名大小写
core.autocrlf=input              # 换行模式为 input,即提交时转换为LF,检出时不转换
core.filemode=false              # 不检查文件权限
core.safecrlf=true               # 拒绝提交包含混合换行符的文件
core.editor=vim
core.repositoryformatversion=0   # Internal variable identifying the repository format and layout version
core.bare=false                  # 默认不创建裸仓库
core.logallrefupdates=true       # log 所有 ref 的更新
core.precomposeunicode=true      # Mac专用选项,开启以便文件名兼容其他系统
push.default=simple                    # 只推送本地当前分支,且与上游分支名字一致
alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
pull.rebase=true                 # 强制开启 rebase 模式
credential.helper store // 记住密码

// 推荐配置
git config --global user.email “mtide@xxx.com"
git config --global user.name=mtide
sudo git config --system core.ignorecase false
sudo git config --system core.autocrlf input
sudo git config --system core.filemode false
sudo git config --system core.safecrlf true
sudo git config --system core.editor vim
sudo git config --system core.repositoryformatversion 0
sudo git config --system core.bare false
sudo git config --system core.logallrefupdates true
sudo git config --system core.precomposeunicode true
sudo git config --system push.default simple
sudo git config --system alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
sudo git config --system pull.rebase true
sudo git config credential.helper store // 记住密码

配置记住密码

[core]
        autocrlf = true
        excludesfile = C:\Users\lixinglong\Documents\gitignore_global.txt
[user]
        name = leo
        email = leo@***.cn
[credential]
    helper = store // 这样配置就会记住密码了

git全局配置修改

$ git config -e --global

进入全局配置文件,击字母i,进入编辑状态,修改里面的内容。

连接远程仓库相关命令

// 查看git远程库信息
$ git remote -v

// 查看remote地址,远程分支,还有本地分支与之相对应关系等一系列信息
$ git remote show origin

远程仓库的移除与重命名

如果想要重命名引用的名字可以运行 git remote rename 去修改一个远程仓库的简写名。 例如,想要将 pb 重命名为 paul,可以用 git remote rename 这样做:

$ git remote rename pb paul
$ git remote
origin
paul

值得注意的是这同样也会修改你的远程分支名字。 那些过去引用 pb/master 的现在会引用 paul/master

如果因为一些原因想要移除一个远程仓库 - 你已经从服务器上搬走了或不再想使用某一个特定的镜像了,又或者某一个贡献者不再贡献了 - 可以使用 git remote rm

$ git remote rm paul
$ git remote
origin

参考文章:
https://blog.csdn.net/weixin_33768153/article/details/81026687
Git官方文档-2.5 Git 基础 - 远程仓库的使用

原文地址:https://www.cnblogs.com/russellyoung/p/Git-pei-zhi-xin-xi-xiang-guan-ming-ling.html