Introduction to git and GitHub, for a fool-proof programming: Git Cheatsheets for Quick Reference

Key Points

General Introduction
  • The course material will be provided through a website and with corresponding PDF.

Beginning with the Terminal
  • Use pwd to show in which folder you are.

  • Use ls to list the files of a folder

  • Use ls -a to show all files and folders

  • Use cd to change the folder

  • Use cd .. to go back one folder

  • Use mkdir to create a folder

  • Use touch to create an empty file

Basics
  • Version control software let’s you track modifications in documents in a structured way

Setting Up Git
  • Use git config with the --global option to configure a user name, email address, editor, and other preferences once per machine.

Creating a Repository
  • git init initializes a repository.

  • Git stores all of its repository data in the .git directory.

Tracking Changes
  • git status shows the status of a repository.

  • Files can be stored in a project’s working directory (which users see), the staging area (where the next commit is being built up) and the local repository (where commits are permanently recorded).

  • git add puts files in the staging area.

  • git commit saves the staged content as a new commit in the local repository.

  • Write a commit message that accurately describes your changes.

Exploring History
  • git diff displays differences between commits.

  • git checkout recovers old versions of files.

Ignoring Things
  • The .gitignore file tells Git what files to ignore.

Remotes in GitHub
  • A local Git repository can be connected to one or more remote repositories.

  • Use the SSH protocol to connect to remote repositories.

  • git push copies changes from a local repository to a remote repository.

  • git pull copies changes from a remote repository to a local repository.

Collaborating
  • git clone copies a remote repository to create a local repository with a remote called origin automatically set up.

Conflicts
  • Conflicts occur when two or more people change the same lines of the same file.

  • The version control system does not allow people to overwrite each other’s changes blindly, but highlights conflicts so that they can be resolved.

Open Science
  • Open scientific work is more useful and more highly cited than closed.

Citation
  • Add a CITATION file to a repository to explain how you want your work cited.

Hosting
  • Projects can be hosted on university servers, on personal domains, or on public forges.

  • Rules regarding intellectual property and storage of sensitive information apply no matter where code and data are hosted.

Using Git from RStudio
  • Using RStudio’s Git integration allows you to version control a project over time.

Using Git with EVE
  • Using git clone from a project you have on GitHub to synchronize on EVE.

  • Push/pull before making changes to both the EVE and local git directories to avoid conflicts

  • Alterntively, create a new branch to work on EVE

Connecting GitHub with Zenodo
  • By connecting on Zenodo with your GitHub credentials, you can toggle automatic archival based on GitHub releases.

Navigating and Searching code on GitHub
  • Using GitHub commit history allows you to get access directly to your code.

  • You can look at specific files, have them as raw version, or acces their history

  • It is possible to select a specific line of code to link to it or cite it

  • Through the settings tab of a project you can collaborators

  • GitHub issues are a good way to keep track of progress, bugs, and ideas on a project

Extra time

Git Cheatsheets for Quick Reference

Glossary

changeset
A group of changes to one or more files that are or will be added to a single commit in a version control repository.
commit
To record the current state of a set of files (a changeset) in a version control repository. As a noun, the result of committing, i.e. a recorded changeset in a repository. If a commit contains changes to multiple files, all of the changes are recorded together.
conflict
A change made by one user of a version control system that is incompatible with changes made by other users. Helping users resolve conflicts is one of version control’s major tasks.
HTTP
The Hypertext Transfer Protocol used for sharing web pages and other data on the World Wide Web.
merge
(a repository): To reconcile two sets of changes to a repository.
protocol
A set of rules that define how one computer communicates with another. Common protocols on the Internet include HTTP and SSH.
remote
(of a repository) A version control repository connected to another, in such way that both can be kept in sync exchanging commits.
repository
A storage area where a version control system stores the full history of commits of a project and information about who changed what, when.
resolve
To eliminate the conflicts between two or more incompatible changes to a file or set of files being managed by a version control system.
revision
A synonym for commit.
SHA-1
SHA-1 hashes is what Git uses to compute identifiers, including for commits. To compute these, Git uses not only the actual change of a commit, but also its metadata (such as date, author, message), including the identifiers of all commits of preceding changes. This makes Git commit IDs virtually unique. I.e., the likelihood that two commits made independently, even of the same change, receive the same ID is exceedingly small.
SSH
The Secure Shell protocol used for secure communication between computers.
timestamp
A record of when a particular event occurred.
version control
A tool for managing changes to a set of files. Each set of changes creates a new commit of the files; the version control system allows users to recover old commits reliably, and helps manage conflicting changes made by different users.