Git workflow#

mg -h output#
Usage: mg <command> [args]

Commands:
  update-commit-date | u - Amend current commit date to now.
  init                   - Create a bare+worktree repository layout for <project>.
  clone | c              - Clone into managed bare/worktree layout.
  show-ignored           - List ignored files.
  show-untracked         - List untracked files.
  switch | s             - Switch to an existing branch worktree. Does not create new branches.
  new-branch | n         - Create a new branch worktree, defaulting base to current branch.
  self-branch | b        - Create tracked worktree branch <branch> from existing <remote>.
  alien-branch           - Create tracked worktree branch <remote>_<branch> from existing <remote>.
  info | i               - Show layout kind, worktree paths, remotes, and branch tracking.
  path                   - Print managed worktree path for <branch>.
  remove-worktree | rw   - Remove a worktree only, keeping local branch refs.
  remove-branch | rb     - Remove merged branch worktree and local branch.
  prune                  - Prune remotes and stale worktree metadata.
  help                   - Show this help text.

mg is the shared git workflow command installed at ~/.local/bin/mg from home/dot_local/bin/executable_mg. It manages the bare-plus-worktree layout I use.

Overview#

  • VVN_DOTFILES_GITHUB_HOST sets default host for mg clone org/repo form.

  • If unset, default host is github.

  • mg detects repository layout automatically: default, parent-bare-siblings, bare-siblings.git, and bare-siblings.

  • mg info prints Layout, Parent, Default worktree, and New sample worktree so worktree placement is explicit before branch creation.

  • switch moves to an existing branch worktree and does not create brand-new branch names.

  • new-branch defaults its base to the current branch on non-bare worktrees; use --from <branch> to override.

  • remove-branch (alias rb) removes merged branch/worktree state and accepts branch names or worktree basenames.

  • remove-worktree (alias rw) removes only the worktree and keeps the local branch ref.

  • switch, new-branch, path, remove-branch, and remove-worktree complete branch names from local branches plus remote-short names.

  • new-branch --from completes base branch names.

  • self-branch and alien-branch complete the second argument from branches that exist on the selected remote.

Common command examples#

Show mg init --example output
mg init –example output#
$ mg init --example
Examples:
  mg init myproject
      Create myproject.git with bare repo and default-branch worktree.

  mkdir sandbox && cd sandbox && mg init myproject
      Create myproject.git inside a dedicated parent folder.

  mg init myproject && cd myproject.git && ls
      Initialize the layout, then inspect bare/ and branch worktree directories.
Show mg clone --example output
mg clone –example output#
$ mg clone --example
Examples:
  mg clone vvnraman myproject
      Clone using org/repo form and create myproject.git layout.

  mg clone git@github.com:vvnraman/myproject
      Clone using a single SSH URL argument.

  mg clone /tmp/test-dir/alpha-remote.git --dest /tmp/test-dir/alpha-copy
      Clone from local bare path into /tmp/test-dir/alpha-copy.git layout.

  mg clone --dest alpha-copy alpha-remote.git
      Clone from a relative local bare path into alpha-copy.git layout.

  mg clone --host github vvnraman myproject
      Clone with an explicit host override.

  VVN_DOTFILES_GITHUB_HOST=github mg clone vvnraman myproject
      Clone using host from environment default.
Show mg switch --example output
mg switch –example output#
$ mg switch --example
Examples:
  mg switch feature-existing
      Jump to existing feature worktree, or create one from origin/upstream.

  mg switch main
      Return to the default branch worktree.

  mg switch fix-login || mg new-branch fix-login
      Switch to an existing branch, or create a new one explicitly.
Show mg new-branch --example output
mg new-branch –example output#
$ mg new-branch --example
Examples:
  mg new-branch feature
      Create a new branch from the current branch and add sibling worktree.

  mg new-branch release/v1
      Create a namespaced branch with matching worktree path.

  mg new-branch --from main hotfix/login
      Create hotfix/login from main, regardless of current branch.

  mg new-branch spike && git -C ../spike status
      Create branch/worktree and inspect repository status there.
Show mg self-branch --example output
mg self-branch –example output#
$ mg self-branch --example
Examples:
  mg self-branch origin feature
      Use existing origin remote and create feature worktree.

  mg self-branch upstream gift-fixme
      Use existing upstream remote and create gift-fixme worktree.
Show mg alien-branch --example output
mg alien-branch –example output#
$ mg alien-branch --example
Examples:
  mg alien-branch alien gift-fixme
      Fetch alien/gift-fixme and create local alien_gift-fixme worktree.

  git -C myproject.git/bare remote add alien git@github.com:alien/myproject && mg alien-branch alien gift-fixme
      Add alien remote manually, then create prefixed local branch/worktree.

mg command help#

Show mg --help output
mg –help output#
$ mg --help
Usage: mg <command> [args]

Commands:
  help [--short] [--short-help] [-h] | --help [--short] [--short-help] [-h]
  -h | --short-help
      Show this help text.

  Aliases: u=update-commit-date, c=clone, s=switch, n=new-branch,
           b=self-branch, i=info, rb=remove-branch, rw=remove-worktree.

  update-commit-date
      Amend current commit date to now. Supports: --example.

  init <project>
      Create a bare+worktree repository layout for <project>. Supports: --help, --example.

  clone [--host <host-alias>] [--dest <project-dir>] <org> <repo>
  clone [--dest <project-dir>] <url-or-local-path>
      Clone into <repo>.git/bare, normalize origin fetch, and create default branch worktree. Supports: --help, --example.

  show-ignored
      List ignored files. Supports: --example.

  show-untracked
      List untracked files. Supports: --example.

  switch <branch>
      Switch to an existing branch worktree, adding local/tracked worktrees when branch exists. Does not create new branches. Supports: --example.

  new-branch [--from <branch>] <branch>
      Create a new branch worktree. Defaults base branch to current branch when on a non-bare worktree. Supports: --help, --example.

  self-branch <remote> <branch>
      Use existing remote, then fetch and create tracked worktree branch <branch>. Supports: --help, --example.

  alien-branch <remote> <branch>
      Fetch existing remote and create tracked worktree branch <remote>_<branch>. Supports: --help, --example.

  info
      Show layout, remotes, remote branches, tracking locals, and worktrees. Supports: --help, --example.

  path <branch>
      Print worktree path for <branch>. Supports: --help, --example.

  remove-worktree [--force] <branch-or-worktree>
      Remove a worktree without deleting its branch. Supports: --help, --example.

  remove-branch [--force] <branch-or-worktree>
      Remove merged branch worktree and local branch. Supports: --help, --example.

  prune
      Prune remotes and stale worktree metadata. Supports: --help, --example.

Options:
  --host <host-alias>
      Supported by: clone only.

  --dest <project-dir>
      Supported by: clone only.

Defaults:
  Host defaults to VVN_DOTFILES_GITHUB_HOST; fallback is github.

Host aliases:
  <host-alias> is your SSH host alias from ~/.ssh/config
  (for example: github -> github.com with User git).
  Show resolved hostname for alias:
    ssh -G github | rg '^hostname '

Implementation details#

  • <host-alias> refers to our SSH alias in ~/.ssh/config.

  • MG_GIT_VERBOSE=1 enables shell tracing for mg command execution.

  • See Git scripts for runtime dispatch, include guards, and wrapper internals.

Relevant changelogs#