• Git config with directory scope, containing multiple repositories


    Git config with directory scope, containing multiple repositories

    based on https://stackoverflow.com/a/44036640/2377961 i think I found a way how it could work.

    first you create different config files for your "custom-scopes" (e.g. professional, freetime, ect.) and add your desired user-config for each scope

    # ~/all-projects.gitconfig
    [user]
       name = TheOperator
    

    .

    # ~/professional.gitconfig
    [user]
       email = yourname@yourwork.com
    

    .

    # ~/freetime.gitconfig
    [user]
       email = yourname@private-email.com
    

    than you add lines like this in your standard gitconfig:

    # ~/.gitconfig
    [include]
        path = all-projects.gitconfig
    [includeIf "gitdir/i:c:/work/"]
        path = professional.gitconfig
    [includeIf "gitdir/i:c:/freetime/"]
        path = freetime.gitconfig 
    

    The directories after "gitdir/i" should match the parents directory of your project groups. In my example you should store your git-repos for freetime-domains e.g. "c:/freetime/my-freetime.domain/.git"

    Can I specify multiple users for myself in .gitconfig?

    With conditional includes in Git 2.13, it is now possible to have multiple user/email coexist on one machine with little work.

    user.gitconfig has my personal name and email. work-user.gitconfig has my work name and email. Both files are at ~ path.

    So my personal name/email applies by default. For c:/work/ dir, my work name/email is applied. For c:/work/github/ dir, my personal name/email is applied. This works as the last setting gets applied.

    # ~/.gitconfig
    [include]
        path = user.gitconfig
    [includeIf "gitdir/i:c:/work/"]
        path = work-user.gitconfig
    [includeIf "gitdir/i:c:/work/github/"]
        path = user.gitconfig
    

    gitdir is case-sensitive and gitdir/i is case-insensitive.

    "gitdir/i:github/" would apply the conditional include for any directory with github in its path.

    Git 2.13 conditional config on windows

    Your global C:/Users/<user-name>/.gitconfig should have this includeIf:

    [includeIf "gitdir:C:/Users/<user-name>/Documents/webstorm/corporate/"]
        path = .gitconfig-work
    

    with having your work Git repos in C:/Users/<user-name>/Documents/webstorm/corporate and the conditional work configuration should be located at C:/Users/<user-name>/.gitconfig-work.

    That's at least working for me in Window's cmd and Cmder. A git config --show-origin --get user.email should than show you from where a config value is loaded/resolved.

    It also seems like the conditional work configuration is only used when issued from within a Git repository.

    C:Users<user-name>Documentswebstormcorporate
    λ git config --show-origin --get user.email
    file:C:/Users/<user-name>/.gitconfig  foo@oss.com
    
    C:Users<user-name>Documentswebstormcorporatesome-repo
    λ git config --show-origin --get user.email
    file:C:/Users/<user-name>/.gitconfig-work  foo@company.com
    
    C:Users<user-name>Documentswebstormcorporatesome-non-repo-dir
    λ git config --show-origin --get user.email
    file:C:/Users/<user-name>/.gitconfig  foo@oss.com
    
  • 相关阅读:
    jquery ajax 后台响应成功,返回正确json但不执行success方法,执行error的问题
    bootstrap轮播组件,大屏幕图片居中效果
    mouseover和mouseout事件在鼠标经过子元素时也会触发
    vertical-align的深入学习
    小技巧
    css字体大小设置em与rem的区别
    子元素的margin-top影响父元素原因和解决办法
    JavaScript随机打乱数组
    JavaScript 获取当月天数
    javaScript 的option触发事件
  • 原文地址:https://www.cnblogs.com/chucklu/p/15214189.html
Copyright © 2020-2023  润新知