在不使用命令行的情况下从 RStudio 初始化 GitHub repo
Initialise GitHub repo from RStudio without Using Command Line
我的任务是在我的工作场所测试 GitHub 培训计划的可行性。由于内部安全,我们不能使用命令行。我正在尝试:
- 初始化一个新的 git 存储库
- 从我当前的 R 项目添加文件
- 提交这些暂存文件
- 推送到新创建的 GitHub 存储库
全部来自 RStudio,使用 git2r 函数。
我在网上找到的每个教程都依赖于命令行或着眼于克隆现有存储库。我找不到任何从本地 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
如果有简单的 link 到综合教程,那将对我有所帮助。 git2r README 专注于连接到现有的存储库。
您收到的错误是因为您没有为 git 提供要推送到的位置。
我认为您正在寻找 remotes
命令 - https://www.rdocumentation.org/packages/git2r/versions/0.23.0/topics/remotes
您可以为此提供本地文件夹路径,不必是远程服务器。
使用一点 google 和一点 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() 命令作为更有效的解决方案。
我的任务是在我的工作场所测试 GitHub 培训计划的可行性。由于内部安全,我们不能使用命令行。我正在尝试:
- 初始化一个新的 git 存储库
- 从我当前的 R 项目添加文件
- 提交这些暂存文件
- 推送到新创建的 GitHub 存储库
全部来自 RStudio,使用 git2r 函数。
我在网上找到的每个教程都依赖于命令行或着眼于克隆现有存储库。我找不到任何从本地 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
如果有简单的 link 到综合教程,那将对我有所帮助。 git2r README 专注于连接到现有的存储库。
您收到的错误是因为您没有为 git 提供要推送到的位置。
我认为您正在寻找 remotes
命令 - https://www.rdocumentation.org/packages/git2r/versions/0.23.0/topics/remotes
您可以为此提供本地文件夹路径,不必是远程服务器。
使用一点 google 和一点 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() 命令作为更有效的解决方案。