Skip to content

Repository files navigation

gitr

GitHub versionCRAN statusR-CMD-checkCodecov test coverageLifecycle: stableLicense: MIT

A light-weight, dependency-free, application programming interface (API) to access system-level Git commands from within R. Contains wrappers and defaults for common data science workflows as well as Zsh plugin aliases (see below). A generalized API syntax is also available. A system installation of Git is required.

If you run into any issues/problems with gitr full documentation of the most recent release can be found at the pkgdown website. If the issue persists I encourage you to consult the issues page and, if appropriate, submit an issue and/or feature request.

Disclaimer

Use at own risk 😺, however, PRs are encouraged for ideas that I’ve missed. The functionality contained in gitr are heavily influenced by my personal data science workflows and may not suit all users. However, if you have an idea that would make the package better, more widely usable, and/or efficient, please submit an issue or pull request.

Installing

The easiest way to install gitr is to install directly from CRAN

install.packages("gitr")

Alternatively install the development version from GitHub:

remotes::install_github("stufield/gitr")

To install a specific tagged release, use:

remotes::install_github("stufield/gitr@v0.0.2")

Loading

library(gitr)

Examples

Here are some basic examples of the functionality grouped by common actions:

Basics

git_version()
#> [1] "2.49.0"
gitr_current_br()
#> [1] "main"
gitr_default_br()
#> [1] "main"
gitr_local_br()
#> [1] "main"

The Core Engine

(git("branch foo"))
#> Running git branch foo#> $status#> [1] 0#> #> $stdout#> [1] ""#> #> $stderr#> [1] ""
git("branch -av")$stdout|>
cat(sep="\n")
#> Running git branch -av #> foo c3b92f7 Added release_notes to Makefile#> * main c3b92f7 Added release_notes to Makefile#> remotes/origin/HEAD -> origin/main#> remotes/origin/bugfix-get-pr-sha ce27db7 Fix bug in get_pr_sha() (#11)#> remotes/origin/gh-pages 7b2749c Built site for gitr@0.1.0.9000: c3b92f7#> remotes/origin/main c3b92f7 Added release_notes to Makefile#> remotes/origin/prep-for-cran bb5a9bf Clean up URLs#> remotes/origin/submit-cran-0.1.0 9d30397 Increment version number#> remotes/origin/update-pkgdown-new-look 0018001 Update GHAs
git("branch -D foo")$stdout#> Running git branch -D foo#> [1] "Deleted branch foo (was c3b92f7)."

Committing

gitr_commit_msgs(n=3L)
#> Running git log --format=%H -n 3#> [[1]]#> [1] "Added release_notes to Makefile" "" #> attr(,"sha")#> [1] "c3b92f7"#> attr(,"author")#> [1] "stu.g.field@gmail.com"#> #> [[2]]#> [1] "Bump to dev version" "" #> attr(,"sha")#> [1] "e8843c7"#> attr(,"author")#> [1] "stu.g.field@gmail.com"#> #> [[3]]#> [1] "Increment version number" "" #> attr(,"sha")#> [1] "9d30397"#> attr(,"author")#> [1] "stu.g.field@gmail.com"
glog(5L)
#> Running git log --oneline --graph --decorate -n 5 #> * c3b92f7 (HEAD -> main, origin/main, origin/HEAD) Added release_notes to Makefile#> * e8843c7 Bump to dev version#> * 9d30397 (tag: v0.1.0, origin/submit-cran-0.1.0) Increment version number#> * dac226e Update CRAN comments for release#> * a475a5e Update NEWS for v0.1.0
git_diffcommits()
git_reset_hard()
git_reset_soft()
git_uncommit()
git_unstage("DESCRIPTION")

Secure Hash Algorithm (SHA-1)

is_sha("d670c93733f3e1d7c95df7f61ebf6ca0476f14e3")
#> [1] TRUE
is_sha(c("foo", "d670c93")) # vectorized#> [1] FALSE TRUE
gitr_trim_sha("d670c93733f3e1d7c95df7f61ebf6ca0476f14e3")
#> [1] "d670c93"
gitr_trim_sha(c("foo", "d670c93")) # vectorized#> [1] "foo" "d670c93"
gitr_current_sha()
#> Running git rev-parse HEAD#> [1] "c3b92f7"

Tags

gitr_recent_tag()
#> [1] "v0.1.0"
gitr_tag_info()
#> tag tag_sha target_sha message author email user#> v0.1.0 v0.1.0 160b5d7 9d30397 Release of v0.1.0 Stu Field <stu.g.field@gmail.com> stu.g.field#> v0.0.2 v0.0.2 4c4805d 2ffe6bd Release of v0.0.2 Stu Field <stu.g.field@gmail.com> stu.g.field#> v0.0.1 v0.0.1 fc7e99a 5e98f89 Release of v0.0.1 Stu Field <stu.g.field@gmail.com> stu.g.field#> tagdate size path#> v0.1.0 Mon Apr 21 08:44:43 2025 -0600 148 /Users/runner/work/gitr/gitr/.git#> v0.0.2 Sat Apr 12 15:50:09 2025 -0600 148 /Users/runner/work/gitr/gitr/.git#> v0.0.1 Wed Feb 15 12:53:58 2023 -0700 148 /Users/runner/work/gitr/gitr/.git

Situation Report

gitr_sitrep()
#> Using Git version: 2.49.0#> #> Current branch: main#> Default branch: main#> #> Repo status:#> Running git status -s #> #> #> Branches:#> Running git branch -a #> * main#> remotes/origin/HEAD -> origin/main#> remotes/origin/bugfix-get-pr-sha#> remotes/origin/gh-pages#> remotes/origin/main#> remotes/origin/prep-for-cran#> remotes/origin/submit-cran-0.1.0#> remotes/origin/update-pkgdown-new-look#> #> Local status:#> ✓ OK#> #> Upstream remotes: origin#> * main c3b92f7 [origin/main] Added release_notes to Makefile#> #> Commit log: main#> Running git log --oneline --graph --decorate -n 5 #> * c3b92f7 (HEAD -> main, origin/main, origin/HEAD) Added release_notes to Makefile#> * e8843c7 Bump to dev version#> * 9d30397 (tag: v0.1.0, origin/submit-cran-0.1.0) Increment version number#> * dac226e Update CRAN comments for release#> * a475a5e Update NEWS for v0.1.0

ZSH-aliases available in gitr

aliasgit command
ga()git add
gst()git status
gss()git status -s
gau()git add -u
gaa()git add --all
gb()git branch
gba()git branch -a
gbd()git branch -d/-D
gdf()git diff <file>
gbnm()git branch --no-merged
gbmm()git branch --merged
gbr()git branch --remote
gac(), gcngit commit --no-verify --no-edit --amend
gcc()git commit
gco()git checkout
gcb()git checkout -b
gcm()git checkout git_default_br()
gcf()git config --list
gnuke()git reset --hard && git clean -dfx
gcmsg()git commit -m
gp()git push
gpu()git push -u
gpd()git push --dry-run
gpf()git push --force-with-lease
gpr()git pull --rebase --autostash -v
glog()git log --oneline --decorate --graph
gwip()git add -u && commit --no-verify -m "wip"
gclean()git clean -f -d
grm()git rm
grmc()git rm --cached
gsta()git stash
gstl()git stash list
gpop(),gstp()git stash pop
gstaa()git stash apply
gstd()git stash drop
gstc()git stash clear
gsts()git stash show --text
gtn()git tag -n
grba()git rebase --abort
grbc()git rebase --continue
grbs()git rebase --skip
grbm()git rebase git_default_br()
grv()git remote -v

Full list of ZSH-aliases

For general reference, here is a list of the available aliases via the git-plugin from Oh-My-Zsh.

See also Oh-My-Zsh for general installation.

Aliases

aliasgit command
gapagit add --patch
gavgit add --verbose
glogagit log --oneline --decorate --graph --all
gupgit pull --rebase
gupvgit pull --rebase -v
gupagit pull --rebase --autostash
gupavgit pull --rebase --autostash -v
gapgit apply
gaptgit apply --3way
gbdagit branch --no-color --merged | command grep -vE ^([+*] | \s*($(git_main_branch) | $(git_develop_branch))\s*$) | command xargs git branch -d 2>/dev/null
gblgit blame -b -w
gbsgit bisect
gbsbgit bisect bad
gbsggit bisect good
gbsrgit bisect reset
gbssgit bisect start
gcagit commit -v -a
gca!git commit -v -a --amend
gcan!git commit -v -a --no-edit --amend
gcans!git commit -v -a -s --no-edit --amend
gcamgit commit -a -m
gcsmgit commit -s -m
gcasgit commit -a -s
gcasmgit commit -a -s -m
gclgit clone --recurse-submodules
gcorgit checkout --recurse-submodules
gcdgit checkout $(git_develop_branch)
gcountgit shortlog -sn
gcpgit cherry-pick
gcpagit cherry-pick --abort
gcpcgit cherry-pick --continue
gcsgit commit -S
gcssgit commit -S -s
gcssmgit commit -S -s -m
gdcagit diff --cached
gdcwgit diff --cached --word-diff
gdctgit describe --tags $(git rev-list --tags --max-count=1)
gdsgit diff --staged
gdtgit diff-tree --no-commit-id --name-only -r
gdupgit diff @{upstream}
gdwgit diff --word-diff
gfgit fetch
gfogit fetch origin
gfggit ls-files | grep
gggit gui citool
ggagit gui citool --amend
ggpurggu
ggpullgit pull origin $(git_current_branch)
ggpushgit push origin $(git_current_branch)
ggsupgit branch --set-upstream-to=origin/$(git_current_branch)
gpsupgit push --set-upstream origin $(git_current_branch)
ghhgit help
gignoregit update-index --assume-unchanged
gignoredgit ls-files -v | grep "^[[:lower:]]"
git-svn-dcommit-pushgit svn dcommit && git push github $(git_main_branch):svntrunk
glgit pull
glggit log --stat
glgpgit log --stat -p
glgggit log --graph
glggagit log --graph --decorate --all
glgmgit log --graph --max-count=10
glogit log --oneline --decorate
glolgit log --graph --pretty
glols="git log --graph --pretty%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat"
glod="git log --graph --pretty%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'"
glods="git log --graph --pretty%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short"
glola="git log --graph --pretty%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all"
gmgit merge
gmomgit merge origin/$(git_main_branch)
gmtlgit mergetool --no-prompt
gmtlvimgit mergetool --no-prompt --tool=vimdiff
gmumgit merge upstream/$(git_main_branch)
gmagit merge --abort
gpf!git push --force
gpoatgit push origin --all && git push origin --tags
gpvgit push -v
grgit remote
gragit remote add
grbgit rebase
grbdgit rebase $(git_develop_branch)
grbigit rebase -i
grbogit rebase --onto
grevgit revert
grhgit reset
grhhgit reset --hard
grohgit reset origin/$(git_current_branch) --hard
grmvgit remote rename
grrmgit remote remove
grsgit restore
grsetgit remote set-url
grssgit restore --source
grstgit restore --staged
grtcd $(git rev-parse --show-toplevel || echo .)
grugit reset --
grupgit remote update
gsbgit status -sb
gsdgit svn dcommit
gshgit show
gsigit submodule init
gspsgit show --pretty=short --show-signature
gsrgit svn rebase
gstugsta --include-untracked
gstallgit stash --all
gsugit submodule update
gswgit switch
gswcgit switch -c
gswmgit switch $(git_main_branch)
gswdgit switch $(git_develop_branch)
gtsgit tag -s
gtvgit tag | sort -V
gtlgtl(){ git tag --sort=-v:refname -n -l ${1}* }; noglob gtl
gunignoregit update-index --no-assume-unchanged
gunwipgit log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1
glumgit pull upstream $(git_main_branch)
gwchgit whatchanged -p --abbrev-commit --pretty=medium
gamgit am
gamcgit am --continue
gamsgit am --skip
gamagit am --abort
gamscpgit am --show-current-patch

LICENSE

Please note that this package is released with a LICENSE. By using in this package you agree to abide by its terms.

About

A light-weight, dependency-free, API to access system-level git commands from within R

Topics

Resources

Security policy

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages