Rstudio won't push to Github branch main - r

I am struggling with Github and Rstudio. I don't know Github very well and I find the commands very confusing.
I read that Github preferred default branch should now be main and not master anymore. So I created my repository and followed instructions for creating a main branch.
First question:
do I need to use main as default branch to create an R package for download? I see that devtools::install_github still has master as default, so I am puzzled because Hadley and his group are usually very reliable.
I set Rstudio both local and origin to main. However, no matter what I do, Rstudio will always push to master (and recreate it if I deleted it) with the command push origin HEAD:refs/heads/master. (why is this command using HEAD:refs... and not just push origin master? If this is the problem, how do I change Rstudio's default?)
I tried git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main from bash to no avail. I can push to main manually with git push origin main but then Git starts nagging that master is behind. This command really pissed off git git config --global push.default main.
Second question:
How do I set Rstudio to push to main (or to both master and main)?

Related

Reactivate Push & Pull buttons in RStudio

For the past three weeks I've been working on my personal iMac, developing a graphical analysis. It was already linked to a GitHub repository, but I kept working locally until I had something substantial to push up to GitHub. Today I tried to push the changes to GitHub and got the message that GitHub no longer supports https: with password authentication.
No problem, I thought. I already had ssh setup and was using it for non-R projects. So, snooping around the Internet, I came across instructions such as these and changed the urls from https to ssh.
But somewhere along the way, RStudio decided to gray out the buttons for Pull & Push under the Git tab.
How does one reactivate the buttons?
Make sure first your SSH URL works from command line:
ssh -Tv git#github.com
cd /path/to/local/repo
git remote -v # do you see an SSH URL git#github.com:<me>/<myrepo>?
git ls-remote # do you see remote branches SHA1?
Then, you would need to reference your private key in your RStudio settings

GitHub branch syncing with the master for no obvious reason

I'm coding in Rstudio and my workflow is along these lines:
make a new branch using Rstudio's UI
add some code or fix a bug
commit code when I'm satisfied and push to GitHub
merge the new code into the master on GitHub
pull the latest master code from GitHub into Rstudio using it's UI
delete any local/remote branches via command line (because Rstudio doesn't have the functionality and doesn't sync with GitHub when it comes to remote branch deletion)
This might not be the most efficient way of doing things (I'm new to git) but it works well enough except for the problem I'm having. Twice now, seemingly at random, I've created a new branch, worked on it and when I've gone back to check something in the master they are identical. The code changes I've made in the branch have already synced with the master.
This is what the last two lines of the History look like:
git history
independant_erp_norm_regressions is the last branch I merged into the master while preprocess_select_global_pars is the current branch which is syncing to the master unduly.
I'm at a loss as to what is going on because I'm doing the same thing as I usually do and haven't been able to find any similar questions on stackoverflow.
Any help would be greatly appreciated (as well as any ways in which I can streamline my workflow).
Ok thanks for the responses guys, as per Tim's reply I decided to commit the changes made to the new branch via Rstudio's UI and check in command line to see what happened behind the scenes. (After that I thought I would do an entire branch/merge via command line to see if the problem persisted or if it was a Rstudio bug). So just before committing the changes Rstudio's git interface showed that Master and my branch were still in sync up to and including having staged files selected together. After committing I used "git show-branch" in command line and it showed that only the correct branch had a new commit, this was mirrored in Rstudio's Git history interface and after merging via GitHub all is well. So it seems like it was just an Rstudio-git bug of sorts.

How to stage, commit and push large amount of changes to GitHub through command line in Rstudio cloud?

I have worked quite a bit in R but I am a novice to GitHub and it's integration with RStudio cloud.
I am trying to update the my git repository through RStudio cloud but couldn't do so through command line (I was able to do so in GUI though).
I have tried
add .
git add -A after installing git2r package in the cloud, but nothing seems to work and I am kind of stuck after googling for half an hour.
Probably you are trying to input the git commands in the Console instead of in the terminal pane. See attached image.
By the way, to avoid adding unwanted files as in the image attached, you may want to create a good gitignore file. See a good tutorial here See a good tutorial from atlassian here

Commit a large number of files in RStudio using GIT panel

In RStudio, if you are dealing with a directory that contains a large number of files, and you want to commit and push the recent changes (that you made on all of them) to your repository, the GUI Git component gets super slow and practically doesn't work. Any idea?
Of course you can ignore the GUI and stick to the command-line Git forever, but if you don't want, a quick jump to the command-line git would solve this problem for now.
The temporary solution that I found is as follows:
Click on the blue-gear icon on the GIT panel, inside RStudio.
Select Shell (a terminal window will pup up!)
Write the add and commit command in the terminal:
{ATTENTION: The following command will commit changes on ALL files! You may want to use what is appropriate for your situation!}
git add -A && git commit -m 'staging all files'
Now you can go back to the GUI Git, and click on push button. All files that you staged in the terminal window, will be pushed up to your repository.
My workaround today was to...
create a man1/ directory in my RStudio project (after force-closing and
relaunching RStudio a few times after I had done something that caused it to hang again),
include man1/ in .gitignore,
move just about everything in man/ to man1/,
delete the .git/index.lock file in the repository,
futz around with RStudio, until it was responsive enough to make the (small) commit of files from man/,
pull and push, so that the remote main was once-again fully synched
copy some files from man1/ to man/, commit these
repeat and rinse of steps 6 and 7, until there's nothing left in man1/
Delete man1/ and its entry in .gitignore
My recipe above isn't one-size-fits-all... for example, you may have run into a "diff is too large" difficulty with RStudio because of a single oversized file, rather than (as I had) with "too many" small files. If you're trying to commit a monstrously-big set of diffs from a single file... you should be including this file in your .gitignore, rather than expecting it to be version-controlled without any difficulty by git. Also, if you're locking up RStudio's Git-interface because of "too many" files being committed simultaneously, your first port of call should I think to commit directories one at a time (but do be sure to push & pull after each commit).
And... I'm not going to complain about this defect in how RStudio interacts with git!
Instead I'll close with some kudos. After just a few days of futzing around with RStudio, I'm finding it to be so much easier than what I remember about hacking on S via emacs in the early 1990s. RStudio handles just about everything (especially the ROxygen documentation workflows) than the emacs/eSS setup that I had been struggling to get fully operational earlier this month.
I'm also impressed with how R has developed since the last time I looked at it -- about 20 years ago! The semantics lurking in corner cases are still very "surprising", to put it mildly ;-) But I do appreciate how it has maintained compatibility with the truly-bizarre and primitive semantics of S while allowing its power-users (which will surely never include me!) to write expressively, elegantly, and with an appropriate balance between concision and the write-only alphabet-soup of APL and its ilk (https://en.wikipedia.org/wiki/Write-only_language)

Pushing Git commits through RStudio

I have started to use Git package inside RStudio . It seems to work fine for Master branch. But adding another branch, you can commit any changes through the GUI but the "push" button doesn't work. Any thoughts how this can be fixed? I can do the push through the terminal but not GUI.
As per Hadley's explanation:
If you try to synchronise this [new] branch to GitHub from inside RStudio,
you’ll notice that push and pull are disabled. To enable them,
you’ll need to first tell Git that your local branch has a remote
equivalent:
git push --set-upstream origin <branch-name> After you’ve done that
once, you can use the pull and push buttons as usual.

Resources