git - beyond basic

but not too far though

This talk

  • What's in a repo
  • What are these things you speak of
  • Some HOWTO

What's in a repo

Hands-on

  • Initialise repository
  • Look inside the `.git` directory
  • Create some commits
  • Create a branch
  • Add a remote

Thesaurus

HEAD

  • Reference to the currently checked-out commit
  • Don't worry too much about it
  • A repository thing
  • Has nothing to do with the working directory or the staging area
  • $ cat ./.git/HEAD
  • As new commits are created, the reference is updated
  • Analogy: cassette tape recorder head
  • SO: What is the HEAD in git?

detached HEAD

  • Not as bad as it sounds
  • When you check out something other than a branch
  • You wouldn't normally commit now
  • If you do want to commit, create a branch first

X_X ohnoe X_X

Remote

  • Remote repository
  • Convention is that the main one is named `origin`
  • Can have more
  • Can be on the same machine
  • Can be on a colleague's machine
  • Yay distributed!

Fork

  • Not an actual git concept
  • Depends on the provider (e.g. GitHub)
  • In GH it creates a remote copy of someone else's repo
  • FOSS that you want to use, but needs some customisation

Tilda, caret

States

  1. Working tree (or directory)
  2. Staging area (or index)
  3. git repository (local)
  4. Remote

States

  • Or working directory
  • A place on the filesystem
  • Where the repository has been cloned
  • The state of the files checked-out and modified

Working tree

States

  • Staging area
  • Changes are marked for commit
  • The next commit will add staged to the next state

Index

States

  • Local repository
  • ./.git directory
  • ...

git repository

States

  • Secret ninja place thingy
  • NOT commits
  • Only on the local repo
  • Others don't see them

stash

Basic advanced commands

stash

  • Not on the working tree
  • Not on the index
  • Not in the history

fetch

  • Fetch refs (branches, tags) from remote
  • Update your local from the remote
  • Not destructive

reset

  • Set HEAD to commit
  • And a bunch of other things
$ git reset [--soft | --mixed | --hard] <commit>
--soft
  • Leaves index and working tree untouched
  • Ready to be committed
--mixed
  • Resets index, but not the working tree
  • Just like you created new files
--hard
  • Resets index and working tree for the tracked files

checkout

  • Switches to the branch
  • Updates HEAD to point at that ref
$ git checkout <branch> | <commit>
  • Undoes all the unstaged changes
$ git checkout -- .

status

  • Differences between index and last commit (HEAD)

cherry-pick

  • Copy a commit on a different branch
  • Useful when only a subset of the changes is needed

rebase

  • Re-creates commits on top of other ones
  • Destructive action, so be careful!
  • Never rebase things that have already been pushed

tread carefully

$ git rebase master topic
  • Takes each commit from the `topic` branch
  • Re-creates on top of the `master` branch

rebase --interactive

  • Alter some successful commits
  • Still a destructive action, so be careful!

tread carefully

$ git rebase --interactive HEAD~3
  • Look at the last 3 commits before HEAD
  • Edit commit message
  • Edit actual changed code from a commit
  • Remove a commit
  • Move a commit's position

Some config things

alias

  • Shorthand if you use the CLI
  • `git st` for `git status`
  • `git lg` for `git log --graph --pretty=...`

HOWTO

Undo things

  • Remove the last commit
  • Remove an older commit
  • ... ?

Remove a commit

  • How far back is it?
  • Are those changes used later?
  • Do you want it gone forever?
  • Do you need the changes?
  • Do you want to move it someplace else?
  • So many cases, so many ways of doing it!

Remove a commit

  • If it's the last commit on a branch
  • Are those changes used later?
  • Do you want it gone forever?
  • Do you need the changes?
  • Do you want to move it someplace else?
  • So many cases, so many ways of doing it!
reset
$ git reset <mode> HEAD~1

Games and books

Interactive tutorials

Reading

Most important

  • Practice, practice, practice

Made with Slides.com