Base

git_is_repo

Return 0 if the current directory is inside a git repository.

Exit codes

  • 0: Inside a git repo; 1 Otherwise

git_root

Get the absolute path to the root of the current git repository.

Exit codes

  • 0: Success; 1 Not in a git repo

Output on stdout

  • Repository root path

git_remote_get

Get the URL for a named git remote.

Example

git_remote_get            # => git@github.com:owner/repo.git
git_remote_get upstream   # => https://github.com/owner/upstream.git

Arguments

  • $1 (string): Remote name (default: origin)

Exit codes

  • 0: Success
  • 1: Not in a git repo or remote not found

Output on stdout

  • Remote URL

git_repo_name

Get the name of the current git repository (from the remote URL, falling back to the directory name).

Exit codes

  • 0: Always

Output on stdout

  • Repository name (without .git suffix)

git_current_branch

Get the name of the current branch.

Exit codes

  • 0: Success; 1 Not in a git repo or detached HEAD

Output on stdout

  • Branch name

git_default_branch

Get the default branch name (main or master) for the repo. Checks remote HEAD reference first; falls back to probing local branches.

Exit codes

  • 0: Found; 1 Unable to determine

Output on stdout

  • Default branch name (e.g. "main" or "master")

git_short_sha

Get the short (7-char) SHA of the current HEAD commit.

Exit codes

  • 0: Success; 1 Not in a git repo

Output on stdout

  • Short SHA string

git_is_tracked

Return 0 if the given file is tracked by git.

Arguments

  • $1 (string): File path

Exit codes

  • 0: Tracked; 1 Not tracked or not in repo

git_newest_commit_date

Print the commit date of the most recent commit that touched a file, in epoch seconds followed by a relative date string, for easy sorting.

Example

git_newest_commit_date README.md   # => 1710000000 (3 weeks ago)

Arguments

  • $1 (string): File path to query

Exit codes

  • 0: Always

Output on stdout

  • Epoch time and relative date, e.g. "1710000000 (3 weeks ago)"

git_cd

Change directory to the top of the current git repository tree, optionally appending a subdirectory path.

Arguments

  • $1 (string): Optional subdirectory path relative to the repo root

Exit codes

  • 0: Success
  • 1: Not in a git repository or cd failed

gcd

Alias for git_cd.

git_delete_branch

Delete one or more git branches locally, remotely, or both. With no branch argument, launches an fzf multi-select prompt.

Arguments

  • $1 (string): Optional mode flag: --local (default), --remote, or --both
  • $2 (string): Branch name(s) to delete, or omit to use fzf interactive selection

Exit codes

  • 0: Always (individual git commands may fail silently)

git

Arguments

  • $1 (string): Git subcommand and arguments (passed through to git)

Exit codes

  • 0: Git command succeeded
  • 1: 'master' reference detected in a 'main'-only repo