| Title: | A Lightweight API for 'Git' |
|---|---|
| Description: | A light-weight, dependency-free, application programming interface (API) to access system-level 'Git' <https://git-scm.com/downloads> commands from within 'R'. Contains wrappers and defaults for common data science workflows as well as 'Zsh' <https://github.com/ohmyzsh/ohmyzsh> plugin aliases. A generalized API syntax is also available. |
| Authors: | Stu Field [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-1024-5859>) |
| Maintainer: | Stu Field <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9000 |
| Built: | 2026-06-04 09:31:10 UTC |
| Source: | https://github.com/stufield/gitr |
Git Branch Utilities
gitr_default_br() gitr_current_br() gitr_local_br()gitr_default_br() gitr_current_br() gitr_local_br()
character(1). The name of the respective
branch if found, otherwise NULL.
gitr_default_br(): gets the default "main" branch, typically either
master, main, or trunk.
gitr_current_br(): gets the current branch.
gitr_local_br(): gets all the local branches.
Checks out as a branch if doesn't exist. Branch
oriented workflow for switching between branches.
If file is passed, checks out the file. A common
shortcut to undoing local changes to a file(s).
Can be a vector of multiple files.
gitr_checkout(branch = NULL, file = NULL)gitr_checkout(branch = NULL, file = NULL)
branch |
|
file |
|
NULL ... invisibly.
## Not run: gitr_checkout("feature-br") gitr_checkout(file = "DESCRIPTION") ## End(Not run)## Not run: gitr_checkout("feature-br") gitr_checkout(file = "DESCRIPTION") ## End(Not run)
Git Commit Utilities
gitr_commit_msgs(sha = NULL, n = 1L) scrape_commits(n) gitr_unstage(file = NULL) gitr_reset_soft(n = 1L) gitr_uncommit() gitr_reset_hard() gitr_diff_commits(top = 1L, n = 2L)gitr_commit_msgs(sha = NULL, n = 1L) scrape_commits(n) gitr_unstage(file = NULL) gitr_reset_soft(n = 1L) gitr_uncommit() gitr_reset_hard() gitr_diff_commits(top = 1L, n = 2L)
sha |
|
n |
|
file |
|
top |
|
NULL ... invisibly.
A list containing commit message entries.
The sha and author of each commit is added as attributes.
gitr_commit_msgs(): gets the commit messages corresponding to the commit sha.
sha can be character(n), but must be valid SHAs
corresponding to commits in the repository.
scrape_commits(): scrapes n commit messages for useful change log commits
to be used to create a NEWS.md.
gitr_unstage(): un-stages a file from the index to the working directory.
Default un-stages all files.
gitr_reset_soft(): un-commits the most recently committed file(s) and
add them to the staging area.
gitr_uncommit(): un-commits the most recently committed
file(s) and add them to the staging area.
Wrapper around gitr_reset_soft()
gitr_reset_hard(): git reset --hard origin/<branch>.
gitr_diff_commits(): gets the diff of the corresponding 2 commits.
Order matters!
## Not run: gitr_commit_msgs() gitr_commit_msgs(n = 3) ## End(Not run)## Not run: gitr_commit_msgs() gitr_commit_msgs(n = 3) ## End(Not run)
Provides functionality for system-level Git commands from within R.
git(..., echo_cmd = TRUE) is_git() git_version()git(..., echo_cmd = TRUE) is_git() git_version()
... |
Additional arguments passed to the system
command-line |
echo_cmd |
|
git(): The system call ... invisibly.
is_git(): logical(1).
git_version(): character(1).
The system version of git.
git(): executes a git command line call from within R.
is_git(): is current working directory a git repository?
git_version(): gets the version of git in use.
## Not run: git("status", "-s") git("reset", "--soft", "HEAD~1") git("tag", "-n") is_git() git_version() ## End(Not run)## Not run: git("status", "-s") git("reset", "--soft", "HEAD~1") git("tag", "-n") is_git() git_version() ## End(Not run)
Lint a commit message for typical commit style and best practices for git.
lint_commit_msg(x)lint_commit_msg(x)
x |
A single commit message from |
integer(1). Invisibly returns the
number of detected lints in the message.
## Not run: lapply(gitr_commit_msgs(7L), lint_commit_msg) ## End(Not run)## Not run: lapply(gitr_commit_msgs(7L), lint_commit_msg) ## End(Not run)
Common Parameters for gitr
n |
|
file |
|
branch |
|
sha |
|
Git PR Utilities
gitr_pr_msgs(branch = NULL) gitr_pr_sha(branch = NULL)gitr_pr_msgs(branch = NULL) gitr_pr_sha(branch = NULL)
branch |
|
gitr_pr_msgs(): see gitr_commit_msgs().
gitr_pr_sha(): character vector of SHAs
corresponding to the PR (relative to the default branch).
gitr_pr_msgs(): gets the commit messages for the current branch
relative to the origin/{main,master} branch in
the remote. Typically these "new" commits
that would be merged as part of a PR to origin/{main,master}.
gitr_pr_sha(): gets the commit SHA-1 a branch (by default current)
relative to the default branch in the remote, usually either
origin/main or origin/master. See gitr_default_br().
If there are un-pushed commit on the current default branch,
it returns them.
## Not run: # SHAs from feature branch differ from default br gitr_pr_sha() # commit messages from the SHAs above # for a PR `branch` -> `remotes/origin/{main,master}` gitr_pr_msgs() # for a feature branch -> default branch gitr_pr_msgs("feature") ## End(Not run)## Not run: # SHAs from feature branch differ from default br gitr_pr_sha() # commit messages from the SHAs above # for a PR `branch` -> `remotes/origin/{main,master}` gitr_pr_msgs() # for a feature branch -> default branch gitr_pr_msgs("feature") ## End(Not run)
SHA1 Utilities
gitr_trim_sha(sha) is_sha(sha) gitr_current_sha()gitr_trim_sha(sha) is_sha(sha) gitr_current_sha()
sha |
|
gitr_trim_sha(): character(1). The trimmed sha.
If sha is not a SHA1 hash, the identical string unchanged.
is_sha(): logical(1). If sha matches the
SHA1 expected pattern.
gitr_current_sha(): character(1). The sha
of the current commit.
gitr_trim_sha(): trims the SHA-1 hash from the default full
length to the human-readable short version.
is_sha(): determines whether strings to be tested are a SHA1 hash
via regular expression ("^[a-f0-9]{5,40}$") match.
gitr_current_sha(): gets the current (most recent commit) SHA.
Get a situation report of the current git repository.
gitr_sitrep()gitr_sitrep()
NULL ... invisibly.
Git Tag Utilities
gitr_recent_tag() gitr_tag_info()gitr_recent_tag() gitr_tag_info()
gitr_recent_tag(): character(1). The most recent tag.
gitr_tag_info(): A data frame summarizing the repository tags.
gitr_recent_tag(): gets the most recent git tag.
gitr_tag_info(): gets a data frame summary of
the current git repository tags.
## Not run: gitr_recent_tag() gitr_tag_info() ## End(Not run)## Not run: gitr_recent_tag() gitr_tag_info() ## End(Not run)
Provides functions to common Z-shell git plugin aliases.
glog(n = 10L) gcc(...) gcmsg(msg = "wip") gco(branch = NULL) gcb(branch = NULL) gpr() gp(...) gpu() gpd() gst() gss() gba() gbd(branch = NULL, force = FALSE) gbmm(branch = gitr_default_br()) gbnm(branch = gitr_default_br()) gbm(branch = NULL) ga(...) gaa() gau() gsta() gstl() gstaa(n = 0) gstd(n = 0) gstc() gsts(text = FALSE) gpop() gstp() gtn() gfa() gac() gwip() gclean(dry_run = TRUE) gdf(file = NULL, staged = FALSE) gpf() gnuke() gcf(global = FALSE) gcm() grm(...) grbc() grba() grbs() grbm() grv()glog(n = 10L) gcc(...) gcmsg(msg = "wip") gco(branch = NULL) gcb(branch = NULL) gpr() gp(...) gpu() gpd() gst() gss() gba() gbd(branch = NULL, force = FALSE) gbmm(branch = gitr_default_br()) gbnm(branch = gitr_default_br()) gbm(branch = NULL) ga(...) gaa() gau() gsta() gstl() gstaa(n = 0) gstd(n = 0) gstc() gsts(text = FALSE) gpop() gstp() gtn() gfa() gac() gwip() gclean(dry_run = TRUE) gdf(file = NULL, staged = FALSE) gpf() gnuke() gcf(global = FALSE) gcm() grm(...) grbc() grba() grbs() grbm() grv()
n |
|
... |
Additional arguments passed to the system
command-line |
msg |
|
branch |
|
force |
|
text |
|
dry_run |
|
file |
A full file path within the repository to diff. |
staged |
|
global |
|
Most aliases invisibly return NULL ... with some exceptions.
glog(): Get the git log in a pretty format for the
n most recent commits.
gcc(): git commit .... To avoid masking the base::gc() function,
this alias has been re-mapped to gcc().
gcmsg(): git commit -m <msg>.
gco(): git checkout.
gcb(): git checkout -b <branch>.
gpr(): git pull --rebase.
gp(): git push.
gpu(): git push -u origin.
gpd(): git push --dry-run.
gst(): git status.
gss(): git status -s.
gba(): git branch -a.
gbd(): git branch -dD.
gbmm(): git branch --merged <branch>.
gbnm(): git branch --no-merged <branch>.
gbm(): git branch -m.
ga(): git add ....
gaa(): git add --all.
gau(): git add -u.
gsta(): git stash.
gstl(): git stash list.
gstaa(): git stash apply.
Note zero-indexing!
gstd(): git stash drop.
Note zero-indexing!
gstc(): git stash clear. Danger!
gsts(): git stash show.
gpop(): git stash pop --quiet --index.
gstp(): See gpop().
gtn(): git tag -n.
gfa(): git fetch --all --prune.
gac(): git commit --no-verify --amend --no-edit.
gwip(): git commit --no-verify -m 'wip'.
gclean(): git clean -f -d.
gdf(): git diff <file>.
gpf(): git push --force-with-lease.
gnuke(): git reset --hard && git clean -df.
gcf(): git config --local or git config --global.
gcm(): Checkout the default branch.
grm(): git rm ....
grbc(): git rebase --continue.
grba(): git rebase --abort.
grbs(): git rebase --skip.
grbm(): git rebase gitr_default_br().
grv(): git remote -v.
## Not run: glog() ## End(Not run)## Not run: glog() ## End(Not run)