Library Carpentry: Introduction to Git: Quick reference

Key Points

What is Git/GitHub?
  • Version control helps track changes to files and projects

  • Git and GitHub are not the same

Getting started with git
  • Git repositories contain metadata about files under version control

  • This metadata enables us to track changes to files over time

  • Git uses a two-stage commit process. Changes to files must first be added to the staging area, then committed to the repository

Sharing your work
  • remote repositories on GitHub help you collaborate and share your work

  • push is a Git verb for sending changes from the local repository to a remote repository

  • pull is a Git verb for bringing changes from a remote repository to the local repository

  • diff is a Git verb for viewing the difference between an edited file and the file’s most recent commit

  • the language of Git can be confusing and intimidating

  • rephrasing commands and drawing concepts can clarify Git’s workflow

GitHub Pages
  • GitHub Pages offer an automated way to create a website that is version controlled and accessible for collaboration

  • Collaborating on a GitHub Pages website uses the same Git/GitHub workflow you learned for collaborating via a GitHub repository

Quick reference

Basics - navigating the shell

print working directory
list directory :
  • -l: list file information
  • -lh: list human readable file information
change directory

Basics - interacting with files

make directory
send file or files to output (in most cases, print to shell)
output first parts of a file or files
output last parts of a file or files
rename or move a file or files. Syntax for renaming a file: mv FILENAME NEWFILENAME
copy a file or files. Syntax: cp FILENAME NEWFILENAME
redirect output. Syntax with cat: cat FILENAME1 FILENAME2 > NEWFILENAME
remove a file or files. NB: USE WITH CAUTION!!!

Basic Git commands

Git cheat sheet handouts:

git init
creates a git repository
git status
view the status of your files in the working directory and staging area
git add
tells git to start tracking a file, or a series of files.
git commit
commits ‘saves’ the staged snapshot to the project history.
git push
commits the staged snapshot to the project history.
git log
history of commits in reverse chronological order.
git diff
shows changes made to files
git pull
Merges upstream changes into your local repository
git remote add origin
add a repository where changes will be stored -

Useful library GitHub repositories

Further reading