Skip to content

Instantly share code, notes, and snippets.

@pushcx
Last active August 29, 2015 14:05
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 pushcx/63844b312cbaa26b85ce to your computer and use it in GitHub Desktop.
Save pushcx/63844b312cbaa26b85ce to your computer and use it in GitHub Desktop.
Introduction to Version Control and Git to Lakefront Web Developers

Introduction to Version Control and Git

Peter Harkins - ph@push.cx - @pushcx - http://push.cx

No photos, please (camera shy); notes will be online at: http://gist.github.com/pushcx

Wifi: Holiday Club / H0lidayclub!

http://git-scm.org Homepage

http://github.com GitHub

GitHub is not Git Bitbucket is another popular Git hosting site

starting a project: git init .

getting started with git itself: git config --global user.name "Peter Harkins" git config --global user.email "ph@push.cx" git config --global color.ui auto config is stored in ~/.gitconfig git help config

core steps:

  1. edit a file or files
  2. git status
  3. git add actors
  4. git status
  5. git commit -m "message"
  6. git status

so what happened? git log git diff

git commit # without -m, to write a longer message git show 640a9 # or whatever the hash starts with

Git commits are named as hashes to uniquely identify them and know that no one has edited history

git checkout 456sadf... to roll back to a specific version from the past

detached HEAD, oh no! it's ok, it just means you're not at the latest commit in a branch

git show 7d4c29:actors # to see a specific file at one commit

to go back to editing at the latest commit: git checkout master

'master' is the default branch branching lets you create alternate versions of reality, switch between them, and merge them

to create a new branch: git checkout -b music

do some work

git commit -m "..." git checkout master

do more work

switch back and forth with checkout, building different histories

git merge # to bring the two branches back together

git cherry-pick 234lkj

merge conflict: when you try to change the same lines of the same file on two branches. Git can't guess which change is 'right', so it's your job to resolve the conflict.

<<<<<<< HEAD
=======
David J. Bowie
>>>>>>> music

git branch

git push share your work with others

git fetch to get the work of others

git merge to merge their work into yours

git pull fetch + merge at the same time

git help command

git clone copy a remote repo to this computer

git add -p to 'patch' and add only parts of files

git stash save git stash pop to carry files between branches, but don't forget you stashed :) git stash list to see stashed commits

GUIs gitk Tower - really nice and friendly, very visual TortoiseGit GitHub for Windows is good there are many more

Resources

http://try.github.io - an in-browser walkthrough tutorial - super helpful

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