Skip to content

Instantly share code, notes, and snippets.

@bwoolley
Created February 24, 2009 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwoolley/69668 to your computer and use it in GitHub Desktop.
Save bwoolley/69668 to your computer and use it in GitHub Desktop.

Learn Git

Intro

  • Talk about SCM in general
  • Talk about distributed SCMs
  • Talk about origins of git
    • created by linus b/c he was sick of perforce
  • Git is more than SCM, it's a filesystem
  • git init
  • talk about .git (verses .svn being everyhere)
  • Look at .git/config
  • make a new file
  • git status
  • git add / git status again
  • git commit / git status again
    • talk about small, atomic commits and why they're good
  • git log
    • not linear, the repository "version" is an SHA1 hash
    • git log -p shows actual diffs

How Git Stores Files

  • talk about how a refernce (the SHA1 hash) doesn't need to be the full hsah
  • git show

Changing existing files

  • change the tile
  • git add the file (or commit with -a - but avoid that if you can)
  • git log again / git log -p again

Adding yet another file

  • git add
  • git commit
  • git log

Removing files

  • file system rm

    • STILL need to stage that change (can use either ADD or RM confusing*)
    • UNSTAGE that change by using git reset HEAD file
  • ASIDE: Talk about .git/HEAD and the concept of HEAD - it's JUST A POINTER TO A REF

  • git rm

    • does two steps in one. Removes file from filesystem AND stages the change right away
    • undo it the same way, unstage with git reset HEAD , then git checkout -- file

Git add interactive

  • Adding untracked files
  • Staging tracked file changes

Customizing Git

  • global options
  • git config --global alias.st status
  • format is "git config [--global] [section].[key] value"

Branching

  • Branches are a way to explore different ideas
  • they bring over unstaged/uncommited changes so you can work in master but decide to make a branch
  • You can bring back your changes by merging
  • Move to the branch you want to merge TO, then "git merge "
  • conflicts
    • resolve on merge, then add the file to the staging area and commit to finish it off

Tagging

  • Just a marker for a specific tree state
  • Kind of like .git/HEAD
  • see them in .git/refs/tags

Remotes

Cloning

  • git clone pulls down a remote repository and sets all the stuff in .git/config
  • git push pushes any commits the remote doesn't yet know about

Gist

  • every pastie on gist.github.com is a repository
  • I created a gist, made a file then pulled down that repo locally
  • Made a local change, added/commited it, then pushed it up
  • saw the change on the website

Forking Gists

  • Duncan forked my gist
  • Then he cloned from his private url (public urls are read only)
  • Made a local change, added/committed/pushed
  • I added duncan's public url as a remote on my repo: git remote add duncan git://gist.github.com/69665.git
  • Merged in his changes (git merge duncan/master)
  • Pushed back to MY gist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment