Skip to content

Instantly share code, notes, and snippets.

@djnavarro
Created February 1, 2021 20:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djnavarro/fb1230ce1bb36d0de729829d819af256 to your computer and use it in GitHub Desktop.
Save djnavarro/fb1230ce1bb36d0de729829d819af256 to your computer and use it in GitHub Desktop.
use gert to scan multiple git repos for changes
library(tidyverse)
library(gert)
git_overview <- function(path) {
# find root folders for all git repos
repo_list <- path %>%
list.dirs() %>%
str_subset("/.git$") %>%
str_remove_all("/.git$")
# retrieve the number of commits ahead/behind for all repos
repo_status <- repo_list %>%
map_dfr(
~ git_ahead_behind(repo = .x) %>%
as_tibble() %>%
mutate(repo = .x) %>%
select(repo, ahead, behind)
)
return(repo_status)
}
# a typical use case for me is to scan for repos in my local
# "~/GitHub folder" that have commits that I have forgotten to
# push to github (or, alternatively, forgotten to pull down
# from github)
git_overview("~/GitHub") %>%
filter(ahead > 0 | behind > 0) %>%
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment