Go back to Fan’s Tex4Econ and Miscellaneous Repository.

Basic git commands

Git Connect to remote

# show all remote url
git remote -v

Check File Status

Check if a particular file has had local changes that have not been commited yet.

Use the git status command, with short -s option:

  • modified: the grepl(’ M ’) check will be true
  • new: the grepl(‘??’) check will be true
  • existing no change: the (st_git_status == ““) check will be true
spg_modified <-
  paste0('git status -s',
         'C:/Users/fan/R4Econ/amto/array/fs_ary_mesh.Rmd')
spg_anewfile <-
  paste0('git status -s',
         'C:/Users/fan/R4Econ/math/differentiation/fs_differentiate_lhopital.Rmd')
spg_nochange <-
  paste0('git status -s',
         'C:/Users/fan/R4Econ/math/func_ineq/fs_atkinson_ces.Rmd')

st_git_status <- toString(system(spg_modified, intern=TRUE))
grepl(' M ', st_git_status, fixed=TRUE)
grepl('?? ', st_git_status, fixed=TRUE)
(st_git_status == "")

st_git_status <- toString(system(spg_anewfile, intern=TRUE))
grepl(' M ', st_git_status, fixed=TRUE)
grepl('?? ', st_git_status, fixed=TRUE)
(st_git_status == "")

st_git_status <- toString(system(spg_nochange, intern=TRUE))
grepl(' M ', st_git_status, fixed=TRUE)
grepl('?? ', st_git_status, fixed=TRUE)
(st_git_status == "")