首页 > 解决方案 > 不使用命令行从 RStudio 初始化 GitHub 存储库

问题描述

我的任务是在我的工作地点测试 GitHub 培训计划的可行性。由于内部安全,我们无法使用命令行。我正在尝试:

全部来自使用 git2r 函数的 RStudio。

我在网上找到的每个教程都依赖于命令行或查看克隆现有存储库。我找不到任何从本地 r 项目创建存储库的过程。

到目前为止的工作流程如下所示:

library(git2r)

repo <- init("C:/local_folder/r_project_folder")

config(repo, user.name, user.email)

cred <- cred_token() # Git PAT is included in the projects renviron file

add(repo, "*")

commit(repo, "Commit message")

push()

返回错误信息:

 Error in 'git2r_push': remote 'origin' does not exist

如果只有一个综合教程的链接,那将对我有所帮助。git2r README 侧重于连接到现有的 repos。

标签: rgitgithubrstudio

解决方案


使用一点谷歌和一些 Hansel Palencias 的建议解决了:

首先在您的存储库页面上创建一个空的 GitHub 存储库,然后输入以下命令:

# Clone existing github repo using url and linking this to your project path
clone(url = "https://github.com/user/name_of_repo.git", local_path = "path")

setwd("path")

# Assign variable repo as current local repository
repo <- repository()

# Configure access rights with github username and profile
config(repo, user.name='user name', user.email='email address')

# Add a PAT in local renviron folder
edit_r_environ()

# Save PAT as cred token
cred <- cred_token()

# Stage changs to commit
add(repo, "file.R")
commit(repo, "Commit message")

# Push changes
push(repo, 'origin', 'refs/heads/master', credentials = cred)

有点破解,但解决了问题。将按照建议尝试使用 remotes() 命令作为更有效的解决方案。


推荐阅读