Skip to content

Latest commit

 

History

History
88 lines (58 loc) · 2.94 KB

git-cheatsheet.md

File metadata and controls

88 lines (58 loc) · 2.94 KB

Git and Github Cheatsheet

This page has some quick info on git that you can use as a reference. This guide will be added to over the course of the semester. Please feel free to make a pull request with any additional information you think may be useful!

Key terms

  • command line: a tool for entering text commands into a computer (varies based on OS). For Mac we use the Terminal app.

  • git: a command line tool for storing and managing changes made to files in a project (usually code)

  • Github: a web app that integrates with git and amplifies its functionality with a web-based interface and a social component

  • repository (repo): the place where the history of your work is stored (.git folder)

  • $: The dollar sign is commonly used to represent the command line. Anything to the right of it is what you enter (ex. $ ls means you enter ls)

  • remote: stored on another computer (usually a server or Github)

  • commit: a single unit of changes to the project. Git works best when commits are small and frequent.

Local git repository consists of three “trees”:

  1. working directory: where all of your files live in their current state

  2. index (staging area): where your changes are staged before you commit them

  3. git directory: where the history of all your changes live (.git folder)

project/              <-- working directory
├── home.html         <-- files under version control
├── style.css
└── .git/             <-- git directory

Command Line Basics

  • pwd
    • print the directory (folder) where you currently are
  • ls
    • list all files in the current directory
  • ls -a
    • list all files in the current directory including hidden files (beginning with a dot)
  • cd your-directory-here
    • move to the specified directory
  • cd ..
    • move to the parent directory (up one level)
  • mkdir new-directory-name
    • make a new directory
  • rm file-name
    • remove specified file (FOREVER! Be careful with this)

Initial git setup

  • git init
    • initialize the current directory to be version controlled by git
  • git config --global user.name your-username
    • set your git username (the same as Github username)
  • git config --global user.email [email protected]
    • set your git email (the same one you use for Github)

Keeping track of where you are

  • git log
  • lists all of the commits in the repository, most recent ones first
  • git status
  • provides information on current changes to your files, and whether those changes have been staged (added to the index)

Basic git workflow

Follow these steps to save your changes as a new version:

  1. stage your files (add them to the index)
  • $ git add -A .
  1. commit changes to files
  • $ git commit -m “brief description of changes”
  1. pull changes made by other people
  • $ git pull
  1. push your changes
  • $ git push