Skip to content

Instantly share code, notes, and snippets.

@omarrr
Last active December 26, 2015 04:38
Show Gist options
  • Save omarrr/7094285 to your computer and use it in GitHub Desktop.
Save omarrr/7094285 to your computer and use it in GitHub Desktop.
GIT cheatsheet

GIT 101

Concepts

Git States

  • Committed: Data is safely stored in your local db
  • Modified: Data changed but not committed to db yet
  • Staged: Changed data marked to go in next commit snapshot

Local Operations

  • Checkout: Git Dir (repo) to Working Dir
  • Stage: Working Dir to Staging Area
  • Commit: Staging Area to Git Dir (repo)

Git Locations

  • Git directory: Storage of metadata and object db
  • Working directory: single checkout of one version of the project
  • Staging Area: Single file with next commit info

Workflow

  • Modify files in Working Dir

  • Stage the files, adding snapshots to Staging Area

  • Commit, takes files in the staging area and stores that snapshot in Git Dir

    [Working Dir] -> Staging -> [Staging Area] -> Commit -> [Git Dir]

File States

  • Tracked: included in last snapshot
    • Unmodified
    • Modified
    • Staged
  • Untracked: not included in last snapshot nor in Staging Area

Clone a repo

git clone [email protected]:omarrr/5nbox.git

Commits

W/ Message

Stage changed files

git add FILE

Revert add

git reset FILE

Commit stage

git commit -m "fixed XYZ"

Skipping Stage

Automatically stages every file that's already tracked, then commits

git commit -a

Probably shouldn't get into the habit of doing this...

Pushing

To repo 'origin' the branch 'master'

git push origin master

Branches

Listing

git branch

List local + remote

git branch -all

Branching

Create

git branch hotfix

Switch

git checkout hotfix

Create + Switch

git checkout -b hotfix

Branch Merging

Checkout destination branch

git checkout master

Merge

git merge hotfix

Open Merge Tool

git mergetool -t opendiff

Branch deletion

git branch -d hotfix

Shortcuts

fetch + merge = pull

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment