knitr::opts_chunk$set(
  eval = FALSE,
  collapse = TRUE,
  comment = "#>"
)

These notes were made whilst going through Jenny Bryan's Happy Git and GitHub for the useR instructions.

Set up Git and GitHub

GitHub

Git

Check Git installed on local machine

Git commands

where git
git --version

Set Git details

usethis::use_git_config set Git user name and email

usethis::use_git_config(user.name = "USERNAME", user.email = "EMAIL")

Check Git user name and email details

Git commands

git config --global --list

Connect RStudio to Git

Cache credentials for HTTPS

usethis::create_github_token Get Personal access taken (PAT), storing token in a password management system

usethis::create_github_token()

gitcreds::gitcreds_set Store credentials in Git credential store

gitcreds::gitcreds_set()

Clone own repositories

Clone own remote repository from GitHub

usethis::create_from_github Clones a remote repository from GitHub, creating a local project and Git repository.

usethis::create_from_github(repo_spec = "HTTPS URL",
                            destdir = "DESTINATION DIRECTORY PATH",
                            fork = FALSE)

Git commands

git clone HTTPS URL

Clone own RStudio project to GitHub

usethis::use_git Makes project a Git repository

usethis::use_git()

Git commands

git init

Git commands

Use Git command if committing large number of files as RStudio GIT panel will freeze

git add -A
git commit -m "COMMIT MESSAGE"
git commit --amend --no-edit

usethis::use_github Create a new repository on GitHub

usethis::use_github()

Git commands

git pull
git push

Work on a branch

Git commands

git branch BRANCH_NAME
git checkout BRANCH_NAME

Git commands

git checkout master
git merge BRANCH_NAME

Git commands

git status
git add EDITED_FILE_NAME
git commit -m "COMMIT MESSAGE"

-- If need to abort merge
git merge --abort

Revert back to previous state

Git commands

git status

Git commands

git reset --hard HEAD

Git commands

git commit --amend -m "New commit message"

Git commands

-- revert to previous commit, saved and staged changes kept
git reset --soft HEAD^

-- revert to previous commut, saved changes kept but now unstaged
git reset HEAD^

-- revert to previous commit, saved and staged changes lost
git reset --hard HEAD^

Git commands

git fetch
git checkout origin/master FILENAME

Clone others repositories

Clone others remote repository from GitHub

In others remote repository on GitHub

In your repositories on GitHub

Git commands

git clone HTTPS URL

In others remote repository on GitHub (so that able to pull changes from other remote repository)

Git commands

git remote add upstream OTHERS REMOTE HTTPS URL

usethis::create_from_github Clones and forks others remote repository from GitHub, creating a copy of the repository on your account in Github, a local project and a Git repository, and adds the others remote repository as an upstream remote repository to allow pulling file changes from this upstream remote.

usethis::create_from_github(repo_spec = "HTTPS URL",
                            destdir = "DESTINATION DIRECTORY PATH", 
                            fork = TRUE)

Git commands

git remote -v

Git commands

git pull upstream master --ff-only
git push

Git commands

git branch BRANCH_NAME
git checkout BRANCH_NAME


gcfrench/store documentation built on May 17, 2024, 5:52 p.m.