git

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddWorktree

func AddWorktree(path, branch, baseRef string) error

AddWorktree creates a new worktree with a new branch from a base ref.

func AddWorktreeFromExisting

func AddWorktreeFromExisting(path, branch string) error

AddWorktreeFromExisting creates a worktree checking out an existing branch.

func AddWorktreeFromRemote

func AddWorktreeFromRemote(path, localBranch, remoteBranch string) error

AddWorktreeFromRemote creates a worktree with a local tracking branch from a remote.

func BranchExists

func BranchExists(name string) bool

BranchExists checks if a local branch exists.

func CurrentBranch

func CurrentBranch() (string, error)

CurrentBranch returns the current branch name, or "" for detached HEAD.

func CurrentBranchIn

func CurrentBranchIn(dir string) (string, error)

CurrentBranchIn returns the current branch for a specific worktree.

func DeleteBranch

func DeleteBranch(name string) error

DeleteBranch force-deletes a local branch.

func DeleteRemoteBranch

func DeleteRemoteBranch(remote, branch string) error

DeleteRemoteBranch deletes a branch on the remote.

func Fetch

func Fetch(remote string, refs ...string) error

Fetch fetches a specific ref from a remote.

func FetchAll

func FetchAll(remote string) error

FetchAll fetches all refs from a remote.

func FetchPrune

func FetchPrune()

FetchPrune fetches and prunes dead remote refs.

func GitDir

func GitDir() (string, error)

GitDir returns the .git directory path (handles worktrees where .git is a file).

func HasChanges

func HasChanges() bool

HasChanges returns true if the working tree has uncommitted changes.

func HasChangesIn

func HasChangesIn(dir string) bool

HasChangesIn returns true if a specific worktree has uncommitted changes.

func IsInsideWorkTree

func IsInsideWorkTree() bool

IsInsideWorkTree returns true if the current directory is inside a git repo.

func IsRebaseInProgress

func IsRebaseInProgress() (bool, error)

IsRebaseInProgress checks if a rebase is currently active.

func LastCommitAge

func LastCommitAge(dir string) string

LastCommitAge returns the relative age of the last commit (e.g., "2 hours ago").

func LastCommitDaysAgo

func LastCommitDaysAgo(dir string) int

LastCommitDaysAgo returns the number of days since the last commit in a directory. Returns -1 if the age cannot be determined.

func MainWorktree

func MainWorktree() (string, error)

MainWorktree returns the path of the main (first) worktree.

func MergeFF

func MergeFF(ref string) (string, error)

MergeFF does a fast-forward merge.

func MergeFFIn added in v1.3.1

func MergeFFIn(dir, ref string) error

MergeFFIn does a fast-forward merge in a specific directory.

func MoveWorktree

func MoveWorktree(oldPath, newPath string) error

MoveWorktree moves a worktree to a new path.

func ParentDir

func ParentDir() (string, error)

ParentDir returns the parent directory of the main worktree (where sibling worktrees are created).

func PotentialConflicts

func PotentialConflicts(baseRef string) ([]string, error)

PotentialConflicts returns files modified on both HEAD and baseRef since they diverged. These files could potentially conflict during a rebase.

func PruneWorktrees

func PruneWorktrees()

PruneWorktrees cleans up stale worktree bookkeeping.

func PushForceWithLease

func PushForceWithLease() error

Push pushes with force-with-lease.

func PushSetUpstream

func PushSetUpstream(remote string) error

PushSetUpstream pushes and sets the upstream.

func ReadStateFile

func ReadStateFile(name string) (string, error)

ReadStateFile reads a state file from the git dir.

func Rebase

func Rebase(onto string) error

Rebase runs `git rebase <onto>` with passthrough output.

func RebaseAbort

func RebaseAbort() error

RebaseAbort aborts an in-progress rebase.

func RebaseAbortIn

func RebaseAbortIn(dir string)

RebaseAbortIn aborts a rebase in a specific directory.

func RebaseContinue

func RebaseContinue() error

RebaseContinue continues an in-progress rebase.

func RebaseIn

func RebaseIn(dir, onto string) error

RebaseIn runs rebase in a specific directory silently. Returns error on conflict.

func RemoteBranchExists

func RemoteBranchExists(name string) bool

RemoteBranchExists checks if a remote branch exists (e.g., "origin/feature").

func RemoveStateFile

func RemoveStateFile(name string)

RemoveStateFile deletes a state file.

func RemoveWorktree

func RemoveWorktree(path string) error

RemoveWorktree removes a worktree (force).

func RenameBranch

func RenameBranch(oldName, newName string) error

RenameBranch renames a local branch.

func RepoName

func RepoName() (string, error)

RepoName returns the basename of the main worktree (the true repo name). Uses MainWorktree() rather than --show-toplevel, which would return the linked worktree's directory name when called from inside one.

func ResolveBranch

func ResolveBranch(name, remote string) (ref string, isRemote bool, err error)

ResolveBranch tries to find a branch ref in order: local, remotes/<name>, remotes/origin/<name>. Returns the ref, whether it's remote, and any error.

func Run

func Run(args ...string) (string, error)

Run executes a git command and returns its trimmed stdout. If the command fails, the error includes stderr.

func RunIn

func RunIn(dir string, args ...string) (string, error)

RunIn executes a git command in a specific directory.

func RunPassthrough

func RunPassthrough(args ...string) error

RunPassthrough executes a git command with stdout/stderr connected to the terminal. Used for commands where the user needs to see real-time output (rebase, push, etc.).

func RunPassthroughIn

func RunPassthroughIn(dir string, args ...string) error

RunPassthroughIn executes a git command in a directory with passthrough I/O.

func RunSilent

func RunSilent(args ...string) error

RunSilent executes a git command and discards all output. Returns only whether it succeeded.

func RunSilentIn

func RunSilentIn(dir string, args ...string) error

RunSilentIn executes a git command in a directory silently.

func SaveStateFile

func SaveStateFile(name, content string) error

SaveStateFile writes the rebase state to a file in the git dir.

func SetUpstream

func SetUpstream(remote, branch string) error

SetUpstream sets the upstream tracking branch.

func StashPop

func StashPop() error

StashPop restores the most recent stash.

func StashPush

func StashPush(message string) error

StashPush stashes uncommitted changes (including untracked files) with a message.

func StateFileExists

func StateFileExists(name string) bool

StateFileExists checks if a state file exists.

func StatusShort

func StatusShort() (string, error)

StatusShort returns the short status output for display.

func TopLevel

func TopLevel() (string, error)

TopLevel returns the absolute path to the repository root.

func UnpushedCountIn

func UnpushedCountIn(dir string) int

UnpushedCountIn returns the number of commits ahead of the upstream.

func Upstream

func Upstream() string

Upstream returns the upstream tracking branch, or "" if none.

func Username

func Username() (string, error)

Username returns the git user's first name, lowercased. e.g., "Michael Williams" → "michael"

Types

type AheadBehind

type AheadBehind struct {
	Ahead  int
	Behind int
}

AheadBehind returns how many commits a branch is ahead/behind a ref.

func GetAheadBehind

func GetAheadBehind(remoteRef string) (AheadBehind, error)

GetAheadBehind computes ahead/behind between HEAD and a remote ref.

func GetAheadBehindIn

func GetAheadBehindIn(dir, remoteRef string) (AheadBehind, error)

GetAheadBehindIn computes ahead/behind for a specific worktree.

type FileChange

type FileChange struct {
	Status string // Two-character status (e.g., "M ", " M", "??", "R ")
	Path   string
	// For renames: original path
	OldPath string
}

FileChange represents a single file change from git status --porcelain.

func ParsePorcelainOutput

func ParsePorcelainOutput(out string) []FileChange

ParsePorcelainOutput parses the output of `git status --porcelain` into FileChanges.

func StatusPorcelain

func StatusPorcelain() ([]FileChange, error)

StatusPorcelain returns parsed file changes.

func StatusPorcelainIn

func StatusPorcelainIn(dir string) ([]FileChange, error)

StatusPorcelainIn returns parsed file changes for a specific directory.

func (FileChange) IsRename

func (f FileChange) IsRename() bool

IsRename returns true if this change is a rename.

type Worktree

type Worktree struct {
	Path   string
	Branch string
}

Worktree represents a git worktree entry.

func ListWorktrees

func ListWorktrees() ([]Worktree, error)

ListWorktrees returns all worktrees from `git worktree list --porcelain`.

func ParseWorktreeList

func ParseWorktreeList(out string) []Worktree

ParseWorktreeList parses the porcelain output of `git worktree list`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL