Presentation for HackMcGill. Intro to Git/Github plus various tips and tricks, all in one.
HackMcGill :: January 29, 2014tips & tricksand:
View Slide
about me- Wendy Liu- 4th year Math & CS- 3 years experience with Git- 137-day Github commit streak- dellsystem on Twitter, Github, IRC
what is git?
what is git?version control system!
svn/perforce: local vs. remotecomparison to other systems
svn/perforce: local vs. remotehg/bzr: faster, more controlcomparison to other systems
svn/perforce: local vs. remotehg/bzr: faster, more controlcvs/rcs: no comparisoncomparison to other systems
backup_dec_1_2012.zip backup_dec_8_2012.zip backup_dec_15_2012.zipbackup_dec_22_2012.zip backup_dec_29_2012.zip backup_jan_5_2012.zipbackup_jan_12_2012.zip backup_jan_19_2012.zip backup_jan_26_2012.zip
report_v1.doc report_v2.doc report_v3.doc report_v4.doc
keeps track of changesenter git.
keeps track of changesextremely flexibleenter git.
keeps track of changesextremely flexibledeveloped by linus torvaldsenter git.
keeps track of changesextremely flexibledeveloped by linus torvaldscompletely free to use (and open source!)enter git.
keeps track of changesextremely flexibledeveloped by linus torvaldscompletely free to use (and open source!)primarily command-lineenter git.
websitewhat is github?
websitecollaborative coding, via gitwhat is github?
websitecollaborative coding, via git(mostly) free to usewhat is github?
websitecollaborative coding, via git(mostly) free to usemajor part of developer ecosystem (esp. OSS)what is github?
why git?
why git?diffs
why git?diffsbackups
why git?diffsbackupscollaboration
what git can do for youversioningeasy collaborationblametracking down bugssafe experimentationstatistics
what github can do for youissue-trackingeven easier collaborationremote backupsaccess your files from anywheregraphical, easy-to-use UI
now: how git works
repositorydirectory on filesystemjust metadata (changes)manual grouping of changes
commitgroup of logically-related changes1 or more files (add/delete/modify)
staging indexCHANGES I WANT IN MY NEXT COMMITALL THE OTHER CHANGES
git commit -m 'test'CHANGES I WANT IN MY NEXT COMMITALL THE OTHER CHANGESa new commit, with message 'test'
CHANGES I WANT IN MY NEXT COMMITALL THE OTHER CHANGESthe commit with message 'test'(nothing here yet)
your computerREMOTE REPOSITORIESLOCAL REPOSITORYsome server another server github
now: git tips
rebasinggit rebase -i [start commit]reorder, reword, edit, squash commits
amendinggit commit --amendstaged changes become part of previous commit
force pushinggit push origin master -fuseful after amending/rebasing
multiple remotesgit remote add origin [url]git remote add upstream [different URL]useful when pulling from other developers
patchgit add --patchstage one chunk at a time
diffinggit diff (unstaged)git diff --cached (staged)git diff --check (whitespace errors)
coloursgit config --global color.ui auto
fix your whitespacegit stripspacegit apply --whitespace=fix
good commit messagesFix bug (50 chars max, capitalised, imperative)Longer description explaining what the commit does.Wrap at 72 characters. Don't forget the blank line.bit.ly/gitcommit
bisectgit bisect (or, "when did this bug first appear?")
ignoring.gitignore (untracked files)git update-index --assume-unchanged (tracked files)git status --ignored
better pullsgit pull vs git fetch & git merge
aliasesgit s = git statusgit add = git add --patchgit ds = git diff --stagedgit amend = git commit --amendgit say = git commit -mgit un = reset --soft HEAD^1
fixing merge conflicts1. Don't panic2. git status3. Look for the <<<4. Stage & commit
moving filesgit mv [source] [destination]instead of:mv [source] [destination]git rm [source]git add [destination]
sensitive datahelp.github.com/articles/remove-sensitive-data
selective staginggit add --update (only tracked files)git add --all (all files)
view configurationgit config --list
pushing to remotesgit push origin mastergit push origin localbranch:remotebranchgit push origin :remotebranch (deletes it)
branch trackinggit push origin master -ugit push origin local:remote -u
stashing editsgit stashgit stash applygit stash pop (applies, then removes from stack)
fixing mistakesgit checkout (undo edits)git reset --soft (keeps edits)git reset --hard (loses edits)
merge strategiesgit merge --strategy=[strategy]strategies: recursive (default), ours, theirs, etc
now: github tips
keyboard shortcutspress ? to bring up the help
issues in commits"Fix #54" -> closes issue #54 from the commit"For #54" -> links to #54 from commit, & vice versa
all from your browseredit, commit, send a pull request... all without leaving your browser
blamewho introduced this line, and when, and why
file renderingmarkup, geoson, csv, and more
integration with traviscontinuous integration (automated testing)
thanks!git-scm.com/bookhelp.github.com