Skip to content

xn-sakina/tanyao

Repository files navigation

tanyao

Git repo clone and multi-account manager

Install

  pnpm i -g tanyao

Usage

  1. Init config on first use :

      tanyao init
  2. Config your base directory and git account info.

  3. Clone repo from anywhere :

      tanyao clone https://github.com/xn-sakina/tanyao.git
      # or
      tanyao clone git@github.com:xn-sakina/tanyao.git
      # or ... 
      tanyao clone https://github.com/xn-sakina/tanyao.git ./tmp-path

    directory structure :

    base
      ├── github.com
         └── xn-sakina
             └── tanyao
      └── gitlab.com
          └── owner
              └── repo

Config

Open ~/.config/tanyao/config.json, set up a code base and git account info :

// ~/.config/tanyao/config.json
{
  "base": "/Users/username/Documents/Code",
  "codebase": [
    {
      "url": "github.com",
      "username": "github-username",
      "email": "i@domain.com"
    },
    {
      "url": "gitlab.com",
      "username": "gitlab-username",
      "email": "admin@domain.com"
    }
  ],
  "alias": {
    "github://": "https://github.com/"
  }
}

Advanced config

Shell alias (Recommend)

# ~/.zshrc

alias -s git="tanyao clone"

This will make the :

$ https://github.com/xn-sakina/tanyao.git
# equal
$ tanyao clone https://github.com/xn-sakina/tanyao.git

See Suffix aliases (-s) in Zsh learn more.

Flexible base

// ~/.config/tanyao/config.json
{
  "base": [
    // use `process.env.CODE_BASE`
    "{CODE_BASE}/dir", 
    // multiple `base`, select when clone
    "Other/Codebase/Path"
  ]
}

Multi GitHub accounts

example:

# .gitconfig

[includeIf "gitdir:~/code_base_name/"]
path = ~/.gitconfig-code_base_name
# ~/.gitconfig-code_base_name

[user]
  name = github_user_id
  email = github_email
[core]
  excludesfile = ~/.gitignore_global
  sshCommand = ssh -i ~/.ssh/id_ed25519
[init]
  defaultBranch = main

See How to Use Two GitHub Accounts on a Macbook the Right Way

Options

--progress

alias: -p

Show git clone progress.

--depth

alias: -d

Git clone depth.

Thanks/Inspiration

  • projj : Manage repository easily.

License

MIT