1 of 17

Slide Notes

DownloadGo Live

Gitty Up

Published on Nov 21, 2015

Git Tips and Tricks

PRESENTATION OUTLINE

gitty up

Roads? Where we're going, we don't need roads

Changes, Not Files

Stage, Then Commit

GIT 101

1.21 gigawatts! 1.21 gigawatts. Great Scott!

Get started

  • git init
  • git add .
  • git commit -m
  • git rm
  • git mv

WHat Has Changed?

  • git log --pretty=oneline --graph --all
  • git diff
aqqqqq

Oops...

  • git reset --hard
  • git checkout  
  • git revert HEAD~2..HEAD

Branch out

Whoa. This is heavy

Branch Basics

  • git branch hotfix101 or checkout -b
  • git checkout hotfix101
  • git merge hotfix101

Problem: 'Need to work on another branch. Don't want to commit'

  • git stash
  • git stash save "message"
  • git stash apply stash@{x}
  • git stash drop stash@{x}
  • git stash branch

PROBLEM: 'I Want ONLY THIS COMMIT FROM '

  • git cherry-pick  

History

What about all that talk about screwing up future events? The space-time continuum?

problem: 'i Left Something out'

  • git commit --amend (-m)

problem: 'There's a typo'

  • fixup!
  • squash!
The difference between squash and fixup is that the during rebase, the squash operation will prompt you to combine the messages of the original and the squash commit, whereas the fixup operation will keep the original message and discard the message from the fixup commit

Problem: 'I want a flat & clean history'

  • git rebase develop
  • git rebase develop -i --autosquash
We could merge the branches and resolve the inevitable conflict by just erasing Marty from history.

But that’s bad workflow here especially since we know that there are some really soon upcoming events coming in the master branch specification that won’t fit well. Merging it in now would just make things worse and we have to still make further changes in the DeLorean branch.

problem: 'Argh! Where did this bug come from?'

  • git bisect start
  • git bisect bad HEAD
  • git bisect good 1b6d
  • git bisect reset

problem: 'I resetted hard, but now i need the changes'

  • git reflog
  • git merge 72bn1
You can use reflog as a safety net: you shouldn’t be worried that a merge, rebase, or some other action will destroy your work since you can find it again using this command.