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
  • When you initialize a Git repository in a directory, Git starts tracking the changes you make inside that directory.

  • This tracking creates a history of the way the files have changed over time.

  • Git uses a two-step process to record changes to your files. Changes to files must first be added to the staging area, then committed to the Git 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

Review
  • 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

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

Interacting with files in the shell

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

Git commands

Git cheat sheet handouts:

git init
create a new local git repository
git status
view the status of your files in the working directory and staging area
git add
tell git to start tracking a file, or a series of files
git commit
save file changes from the staging area permanently to the project history
git push
upload all commits to a remote repository, such as GitHub
git log
show history of commits in reverse chronological order
git diff
show changes made to tracked files
git pull
download upstream changes and merge them into your local repository
git remote add origin
add a remote repository named ‘origin’, to upload changes to or download changes from

Useful library GitHub repositories

Further reading