Chapter 11 Github

Der Beitrag wurde das letzte mal am 04 November, 2021 editiert

Github ist ein sogenanntes version control system, freeware und wird vorallem bei der Softwareentwicklung genutzt. Der Vorteil ist, dass eine Vielzahl von Leuten an ein und demselben Projekt gleichzeitig arbeiten kann. Die Weiterentwicklung von Dateien und Projekten lassen sich mit github reproduzierbar nachvollziehen. Abgelegt werden Projekte in repositories, kurz repos.

Git manages the evolution of a set of files – called a repository – in a sane, highly structured way (such as “Track Changes” features from Microsoft Word on steroids)

Schritt 1:

  • Installiere git für windows here
    • NOTE: When asked about “Adjusting your PATH environment”, make sure to select “Git from the command line and also from 3rd-party software”. Otherwise, we believe it is good to accept the defaults.
    • Note that RStudio for Windows prefers for Git to be installed below C:/Prgram Files and this appears to be the default.
    • Now: Introduce yourself to Git
# library(usethis)
## What user name should you give to Git? This does not have to be your GitHub user name, although it can be. Another good option is your actual first name and last name.

## What email should you give to Git? This must be the email associated with your GitHub account.
#use_git_config(user.name = "XY", user.email = "XY@gmx.de")

## Create a github tokken for secure access to github. Then, you don't need to access all the time your personal item
# usethis::create_github_token()

## Activate your tokken PAT = Personal Access Tokken
# library(gitcreds)
# gitcreds_set()
  • Use a Git client

    • “Git” is really just a collection of individual commands you execute in the shell (Appendix A). This interface is not appealing for everyone. Some may prefer to do Git operations via a client with a graphical interface. Git and your Git client are not the same thing, just like R and RStudio are not the same thing. A Git client and an integrated development environment, such as RStudio, are not necessary to use Git or R, respectively.
    • Sourcetree is a recommended option
  • The most basic commands are listed below:

    • pwd (print working directory). Shows directory or “folder” you are currently operating in. This is not necessarily the same as the R working directory you get from getwd().

    • ls (list files). Shows the files in the current working directory. This is equivalent to looking at the files in your Finder/Explorer/File Manager. Use ls -a to also list hidden files, such as .Rhistory and .git.

      • Use arrow-up and arrow-down to repeat previous commands. Or search for previous commands with CTRL + r.
  • A few Git commands:

    • git status is the most used git command and informs you of your current branch, any changes or untracked files, and whether you are in sync with your remotes.
    • git remote -v lists all remotes. Very useful for making sure git knows about your remote and that the remote address is correct.
    • git remote add origin GITHUB_URL adds the remote GITHUB_URL with nickname origin.
    • git remote set-url origin GITHUB_URL changes the remote url of origin to GITHUB_URL. This way you can fix typos in the remote url.
  • Clone the new GitHub repository to your computer via RStudio

    • In RStudio, start a new Project:
    • File > New Project > Version Control > Git.
    • In “Repository URL”, paste the URL of your new GitHub repository.