usethis icon indicating copy to clipboard operation
usethis copied to clipboard

Push to Github on an already created repository

Open roroba opened this issue 1 year ago • 6 comments

I am trying to push to Github on an already created repository. I use usethis to clone a Repo, and now I wanna update and push some new files, lamentably I have some error: Repo already exists, but my goal is push only new files. I tried literally hundreds of times,

library(usethis)

create_from_github("site99999/BaseDatos")

v Setting `fork = FALSE`
v Creating 'C:/Users/roro999999/Desktop/BaseDatos/'
v Cloning repo from 'https://github.com/site9999/BaseDatos.git' into 'C:/Users/roro9999999/Desktop/BaseDatos'
v Setting active project to 'C:/Users/roro999999/Desktop/BaseDatos'
i Default branch is 'main'


use_git(message = "Archivos subidos por Rodrigo")

#My goal is push only this 3 new files to my Repo:
There are 3 uncommitted files:
* '.gitignore'
* 'R/'
* 'SQL/'
Is it ok to commit them?

1: Absolutely not
2: Nope
3: For sure

3

use_github(private=T)

Error: This repo already has an 'origin' remote, with value 'https://github.com/site99999/BaseDatos.git'.

#Here I change the origin to my personal repo
use_git_remote("origin", url = NULL, overwrite = T)

#Here I tried to push
use_github(private=T)

Error: Repo 'roro999999/BaseDatos' already exists on 'github.com'

My Github configuration:

* Personal access token for 'https://github.com': '<discovered>'
* GitHub user: 'roro9999999'
* Token scopes: 'admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, repo, user, workflow, write:discussion, write:packages'
* Email(s): '[email protected] (primary)'
Git repo for current project
* Active usethis project: 'C:/Users/roro999999/Desktop/BaseDatosPMG'
* Default branch: 'main'
* Current local branch -> remote tracking branch:
  'main' -> 'origin/main'
GitHub remote configuration
* Type = 'ours'
* Host = 'https://github.com'
* Config supports a pull request = TRUE
* origin = 'site99999/BaseDatos' (can push)
* upstream = <not configured>
* Desc = 'origin' is both the source and primary repo.

roroba avatar Aug 05 '22 12:08 roroba

Unless I am misunderstanding your question, once you have created a remote, use_github()'s job is done.

At this point, you should be able to use the git commit/pull/push capability in the IDE or the command line.

If you want something in R, you can use the gert package to git_commit(), git_pull(), and git_push(), and a whole lot of other things

ijlyttle avatar Aug 05 '22 15:08 ijlyttle

I can create once a remote with use_github but when I wanna push new files to the same repo I get the error: Repo 'roro999999/BaseDatos' already exists on 'github.com'


use_git(message = "Archivos subidos por Rodrigo")
There are 3 uncommitted files:
* '.gitignore'
* 'R/'
* 'SQL/'
Is it ok to commit them?

1: Absolutely not
2: Nope
3: For sure

3

#Here I tried to push
use_github(private=T)

Error: Repo 'roro999999/BaseDatos' already exists on 'github.com'

Should I delete the old repo and push the original repo with 3 new files??.

I thought that use_github() should push only new files in a already exists repo and overwrite or omit older files.

Anyway I will try gert package, Thanks for the information.

roroba avatar Aug 05 '22 16:08 roroba

use_github() does push files, but it does so after trying to create the repo at GitHub.

Its primary purpose is to help you create the repo at GitHub, pushing files is just something it does at the end to bring things into sync.

ijlyttle avatar Aug 05 '22 19:08 ijlyttle

Do you know some command that I should use instead use_github, I have look but none succesfull.

I was looking for a command to just push files but not create in usethis library.

roroba avatar Aug 05 '22 21:08 roroba

Not in usethis, but gert hasgit_commit(), git_pull(), and git_push().

The gert package gets installed as a dependency of usethis.

ijlyttle avatar Aug 05 '22 23:08 ijlyttle

Thanks for your comments, I will use gets package!

Regards Rodrigo

roroba avatar Aug 05 '22 23:08 roroba

Thanks @ijlyttle for clarifying that the usethis functions like use_github() implement one-time setup. We generally use command line git, a client like the Git pane in RStudio or a standalone application like GitKraken, or the R package gert for day-to-day git operations, like commit / push / pull.

jennybc avatar Aug 29 '22 21:08 jennybc