Set up Git
I highly recommend version control to improve your workflow when writing code, papers, lectures, seminars, etc. I use Git which I recommend to my graduate students so that we are all on the same page, but there are other options.
I also highly recommend backing up your work. This can be combined with a version control system by utilizing a remote repository. I use GitHub to host my repository since GitHub provides unlimited open source repositories, unlimited private repositories with the personal plan ($7/month) or an academic discount. To make a private repository public, you just have to hit a button which makes GitHub ideal for reproducible code, manuscripts, etc. An alternative is Bitbucket which provides unlimited private repositories (without a fee or discount), but you must pay for public repositories. In the event you wanted to make a repository public that was housed at Bitbucket, you could export the repository to GitHub. For those affiliated with Iowa State, there are two GitLab repositories available: EcE and LAS.
Setting Git up from a new computer.
git config --global user.name "YOUR NAME" git config --global user.email "YOUR EMAIL ADDRESS" git config --global push.default simple
as well as setting up your authentication. For authentication, I use SSH and thus I generate an SSH key on each computer I use and for each remote destination I use. Make sure to test the SSH connection.
How to write Git commits
I found this page useful in understanding how to write Git commits. Basically, the subject should finish the sentence “If this commit is accepted, it will …”. Then the body of the message tells that what and why (not the how since that is already in the code).
Git from the command line
git clone email@example.com:<username>/<repo>.git
to create a local of the desired repository. Always
whenever you start working in a repository,
git add <filename>
to stage changes to
to check what files might need to be staged,
git commit -m "message"
to commit the changes, and
to push those changes to the remote repository.
How to start an R package in RStudio with a Git repository
The instructions are from here:
- Create empty repository on github (I will use name rpackage in this example)
- Create package locally using devtools, create(“rpackage”) (this will create rpackage folder)
- Create new project in RStudio (Create project from: Existing directory) and choose rpackage directory
- In RStudio go to Tools/Shell… and type git init
- Reopen the project (this will refresh the Git tab)
Start Git/More/Shell and type
git add * git commit -m “first commit” git remote add origin firstname.lastname@example.org:[username]/rpackage.git git push -u origin master