Skip to content
@deckyard/git

git cheatsheet

Every export of @deckyard/git. Guides are listed in the introduction.

jennifer
import "@deckyard/git/" as git;

Every failure is Error{kind: "git"}. A c argument is a Config, an r a Repo. Revisions and paths that may be "" say so in the guides.

Constants

ConstantValueMeaning
ERROR_KIND"git"the kind of every error the deck throws

Types

Config

FieldMeaning
binary as stringthe git program
timeoutMs as inthow long one command may run
protocols as list of stringthe transports remotes may use
hooks as boolwhether the repository's hooks run
name as stringthe author and committer name; "" for git's
email as stringtheir email; "" for git's

Repo

FieldMeaning
dir as stringthe absolute top-level directory
config as Configthe configuration

Status

FieldMeaning
head as stringthe commit checked out; "" before the first
branch as stringthe branch; "" when detached
upstream as stringthe branch it tracks
ahead as intcommits not on the upstream
behind as intupstream commits not on it
changes as list of Changechanged and untracked files

Change

FieldMeaning
path as stringthe path
origPath as stringthe path before a rename
staged as stringthe index's letter, . for none
unstaged as stringthe working tree's letter
kind as stringchanged, renamed, conflict, untracked

Commit

FieldMeaning
hash as stringits id
parents as list of stringits parents' ids
author as stringthe author's name
authorEmail as stringthe author's email
authorTime as intUnix seconds
committer as stringthe committer's name
committerEmail as stringthe committer's email
committerTime as intUnix seconds
subject as stringthe first line
body as stringthe rest of the message

FileStat

FieldMeaning
path as stringthe path
oldPath as stringthe path before a rename
added as intlines added
removed as intlines removed
binary as boolwhether git saw a binary file

FileChange

FieldMeaning
status as stringA, M, D, R, C, T, U
path as stringthe path
oldPath as stringthe path before a rename or copy

BlameLine

FieldMeaning
line as intthe line number, from 1
hash as stringthe commit that last changed it
author as stringits author
authorEmail as stringthe author's email
authorTime as intUnix seconds
text as stringthe line

TreeEntry

FieldMeaning
path as stringthe path from the top level
type as stringblob, tree or commit
mode as stringe.g. 100644
hash as stringthe object id
size as intbytes; 0 for a tree

Branch

FieldMeaning
name as stringe.g. main, origin/main
hash as stringthe commit
upstream as stringthe branch it tracks
current as boolwhether it is checked out
ahead as intcommits not on the upstream
behind as intupstream commits not on it
gone as boolwhether the upstream was deleted

Tag

FieldMeaning
name as stringe.g. v1.2.0
hash as stringthe commit it points to
annotated as boolwhether it has its own message
message as stringits subject

Remote

FieldMeaning
name as stringe.g. origin
url as stringwhere it fetches from
pushUrl as stringwhere it pushes to

Ref

FieldMeaning
name as stringe.g. refs/heads/main
hash as stringthe object

Merge

FieldMeaning
merged as boolwhether it is done
conflicts as list of stringthe files in conflict

Configuration

FunctionReturnsDoes
git.config()Configsafe defaults
git.withBinary(c, binary)Configanother git program
git.withTimeout(c, ms)Configper-command timeout, at least 1000
git.withProtocols(c, protocols)Configthe transports remotes may use; default https, ssh
git.withHooks(c, on)Configlet the repository's hooks run
git.withIdentity(c, name, email)Configcommit as this person
git.version(c)stringthe git version line
git.available(c)boolwhether git runs

Repositories

FunctionReturnsDoes
git.open(c, dir)Repoa repository at its top level
git.isRepo(c, dir)boolwhether open would accept it
git.create(c, dir, bare)Repogit init
git.clone(c, url, dir)Repoclone
git.cloneWith(c, url, dir, branch, depth)Repoclone one branch or a shallow history
git.run(r, args)stringgit with your own, unchecked arguments

Working tree

FunctionReturnsDoes
git.status(r)Statusbranch, upstream, changed files
git.isClean(r)boolno changes, no untracked files
git.add(r, paths)nullstage files
git.addAll(r)nullstage everything
git.remove(r, paths)nulldelete files, stage that
git.unstage(r, paths)nulltake files out of the next commit
git.restore(r, paths)nulldiscard working-tree changes
git.commit(r, message)stringcommit what is staged; the id
git.amend(r, message)stringreplace the last commit; the id
git.stash(r, message)boolput changes aside; false when none
git.stashPop(r)nullbring them back

History

FunctionReturnsDoes
git.log(r, rev, path, limit)list of Commitcommits, newest first
git.show(r, rev)Commitone commit
git.diff(r, base, target)stringthe patch
git.stagedDiff(r)stringthe patch of what is staged
git.diffStat(r, base, target)list of FileStatlines added and removed per file
git.changes(r, base, target)list of FileChangewhich files changed, and how
git.blame(r, rev, path)list of BlameLinewho last changed each line
git.describe(r, rev)stringa name from the nearest tag
git.readFile(r, rev, path)stringa text file at a revision
git.readBytes(r, rev, path)bytesany file at a revision
git.listTree(r, rev, dir, recursive)list of TreeEntrya directory at a revision
git.archive(r, rev, file)null.zip, .tar or .tar.gz of a revision

Branches and tags

FunctionReturnsDoes
git.revParse(r, rev)stringthe commit id a revision names
git.hasCommits(r)boolfalse for an empty repository
git.branches(r)list of Branchthe local branches
git.remoteBranches(r)list of Branchthe remote-tracking branches
git.currentBranch(r)stringthe branch checked out; "" when detached
git.createBranch(r, name, start)nullcreate a branch
git.deleteBranch(r, name, force)nulldelete a branch
git.switchTo(r, name)nullcheck a branch out
git.detach(r, rev)nullcheck a revision out, no branch
git.setUpstream(r, branch, upstream)nullmake a branch track a remote one
git.tags(r)list of Tagthe tags
git.createTag(r, name, rev, message)nulla tag; annotated with a message
git.deleteTag(r, name)nulldelete a tag
git.mergeBase(r, a, b)stringwhere two revisions forked
git.isAncestor(r, ancestor, rev)boolwhether one is in the other's history
git.merge(r, rev, mode)Mergemerge; ff, ff-only or no-ff
git.abortMerge(r)nullgive up a merge in conflict

Remotes

FunctionReturnsDoes
git.remotes(r)list of Remotethe remotes
git.addRemote(r, name, url)nulladd one
git.removeRemote(r, name)nullremove one
git.setRemoteUrl(r, name, url)nullpoint one elsewhere
git.fetch(r, remote)nullfetch and prune; "" for all
git.pull(r, remote, branch)nullfetch and fast-forward
git.push(r, remote, refspec, force)nullpush; force is --force-with-lease
git.pushTags(r, remote)nullpush every tag
git.lsRemote(c, url)list of Refa remote's refs, without cloning