Git中的配置操作

690 阅读2分钟

Git中的配置操作

1.配置文件存放的3个位置

  • 1.项目配置文件: 当前的找个项目生效,其他的项目就不生效了

    // 🌵设置:
    git config --local user.name "bulala"
    git config --local user.email "bulabualbula.@qq.com"
    
    // 🌵修改编辑:
    vim .git/config 
    
  • 2.全局的配置文件:

    // 🌵设置:
    git config --global user.name "bulala"
    git config --global user.email "bulabualbula.@qq.com"
    
    // 🌵修改编辑:
    vim ~/.gitconfig 
    
  • 3.系统配置文件:

    // 🌵设置:(对于下面的命令是需要有root权限的,不然是写不进去的)
    git config --system user.name "bulala"
    git config --system user.email "bulabualbula.@qq.com"
    
    // 🌵文件存在的目录:
    /etc/.gitconfig
    

    🤪平时用的比较多的就是1和2

2.Git免密登录

三种形式:

  • url中体现: 通过给提交的url中添加用户名和密码标识来实现提交免密登录

    原来的地址:https://gitee.com/dbhotlovelife/dbhot.git
    修改原来的地址:https://用户名:密码@gitee.com/dbhotlovelife/dbhot.git
    
    git remote add origin https://用户名:密码@gitee.com/dbhotlovelife/dbhot.git
    
  • SSH实现:

    1.生成公钥和私钥(生成的公钥和私钥默认存在了~/.ssh中)
    //公钥 ~/.ssh/id_rsa.pub
    //私钥 ~/.ssh/id_rsa
    ssh-keygen -r rsa
    
    2.拷贝公钥的内容并设置到github中
    cat ~/.ssh/id_rsa.pub
    
    3.在git本地项目中配置ssh地址 git remote add origin  + ssh地址
    
  • git自动管理凭证:(就是自动记录了自己提交的代码)

3.gitignore忽略文件:

//项目目录下创建.gitignore文件并编辑
vim .gitignore

//.gitignore中输入需要被git忽略监测的文件名字即可,下面忽略的是.gitignore文件自己
.gitignore   //忽略.gitignore文件自己
*.h //不管所有.h结尾的文件
files/  //不管文件夹fiels中的内容

有些项目本地有数据库,管理的时候只希望推送代码不希望推送数据库,那么就需要使用gitignore来处理下

github中gitignore地址: github.com/github/giti…