r - 不使用命令行从 RStudio 初始化 GitHub 存储库
问题描述
我的任务是在我的工作地点测试 GitHub 培训计划的可行性。由于内部安全,我们无法使用命令行。我正在尝试:
- 初始化一个新的 git 仓库
- 从我当前的 R 项目中添加文件
- 提交这些暂存文件
- 推送到新创建的 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。
解决方案
使用一点谷歌和一些 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() 命令作为更有效的解决方案。
推荐阅读
- node.js - node_redis(npm redis模块)是否支持redis集群模式或者我们必须使用ioredis?
- matlab - 使用 fplot 函数时如何矢量化?
- r - 将字符串与 for 循环 -R 配对
- json - 使用“JSON”列的 Laravel 5 关系
- javascript - 使用媒体查询的 css 图像交换移动与桌面
- python - 请求 Maya Python 协助:根据文本字段内容连接属性
- apache-flink - 缓冲池在 POJO 类型上被破坏
- r - 在 ggplot2 中使用 scale_color_manual 时顺序错误
- python - (sqlite3.OperationalError) 无法从使用 Chatterbot 的事务中更改为 wal 模式
- mysql - 每个表上都有租户 ID 的多租户数据库