#git-config #repository #tool #username #git-repository #email #command-line-tool

app setgitconfig-rs

Set proper git username and email based on the current repository you are in

6 releases (3 breaking)

0.4.0 Sep 22, 2021
0.3.0 Jul 2, 2021
0.2.0 Aug 26, 2020
0.1.2 Aug 19, 2019

#2780 in Command line utilities

MIT license

13KB
130 lines

Build Status Tag

setgitconfig-rs

Sets correct username and useremail for your git-url based on a configuration file.

Use case:

We work on several repositories from different version control providers. Sometime our username and emails are different and we need to set the git config for each of them otherwise the repositories do not detect it.

This binary solves exactly that, based on a simple toml file.

Configuration:

  • Install the binary using

    • cargo: cargo install setgitconfig-rs
      • Put this in your bashrc
        PROMPT_COMMAND="~/.cargo/bin/setgitconfig; $PROMPT_COMMAND"
        
    • From Releases
      • Download the binary
      • Make it executable chmod +x setgitconfig
      • Copy this in your path, for e.g. sudo mv setgitconfig /usr/local/bin/setgitconfig
      • Put this in your ~/.bashrc
        PROMPT_COMMAND="/usr/local/bin/setgitconfig; $PROMPT_COMMAND"
        
  • Just create a directory in your user's home

    mkdir -p ~/.config/setgitconfig

  • Create a file like this:

    touch ~/.config/setgitconfig/config.toml

  • Content of the file can look like this

    $ cat ~/.config/setgitconfig/config.toml
    
    [[repositories]]
    username= "Ankur Srivastava"
    email = "myuser@xmail.com"
    giturl = "github.com"
    [[repositories]]
    username= "Ankur Srivastava"
    email = "myuserfor-github@xmail.com"
    giturl = "gitlab.com"
    

Debugging:

In case the binary is not working as expected, simply run the following:

RUST_LOG=debug path/to/setgitconfig

Dependencies

~14–25MB
~434K SLoC