May the git --force be with you

May the git --force be with you

Talk discussing Git workflow and the controversial --force flag

6bf91645fc931c4c7f3d5549c4b7e59e?s=128

Derrick Parkhurst

August 06, 2014
Tweet

Transcript

  1. Intentional Git may the git --force be with you

  2. Git is the Death Star of RCS

  3. Thisa bad. Thisa veery bad.

  4. You cannot control it. This is a dangerous time for

    you, when you will be tempted by the Dark Side of the Force.
  5. Do... or do not. There is no try.

  6. The Journey of a Git Jedi

  7. Git is a Distributed RCS

  8. Cloning a repository $ git clone https://github.com/PeopleAdmin/portals.git

  9. Modifed, Staged, Committed

  10. Git Checkout Checkout a branch $ git checkout {branch name}

    List all branches in the repository $ git branch Create a new branch $ git checkout -b {new branch name}
  11. Modifed, Staged, Committed

  12. git add Add a fle to the Staging Area $

    git add Add all modifed fles to the Staging Area $ git add -a
  13. git rm Remove fle from os and stage a fle

    removal $ git rm flename
  14. Modifed, Staged, Committed

  15. Git Commit Edit commit message in your editor $ git

    commit Commit message on command line $ git commit -m 'adds some functionality' Each commit gets a SHA (long or short) d670460b4b4aece5915caf5c68d12f560a9fe3e4
  16. Git Commit --> git commit -m 'my commit message' [master

    92efac1] my commit message 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 config.yaml create mode 100644 script.rb
  17. Modifed, Staged, Committed

  18. Tracked vs Untracked Files

  19. git status --> git status On branch master Your branch

    is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: script.rb Untracked files: (use "git add <file>..." to include in what will be committed) config.yaml
  20. git diff Compare working directory (unstaged changes) to last comm

    $ git diff Compare staged changes to last commit $ git diff --cached
  21. git diff --> git diff diff --git a/confg.yaml b/confg.yaml index

    e69de29..81bf67e 100644 --- a/confg.yaml +++ b/confg.yaml @@ -0,0 +1,3 @@ +--- +frst_name: "Luke" +last_name: "Skywalker"
  22. git reset To unstage a fle (fles that have not

    been committed) $ git reset {SHA} {flename} Reset a single fle from the head of the current branch $ git reset HEAD benchmarks.rb Reset all fles from the head of the current branch $ git reset HEAD
  23. git checkout Retrieve a committed fle and place it in

    your working directory $ git checkout {SHA} {flename} Retrieve a fle from the HEAD of the current branch $ git checkout benchmarks.rb Retrieve a fle from any commit in the repository $ git checkout 085bb3b benchmarks.rb
  24. A Git branch

  25. git log --> git log commit 92efac1f814b2a02b554ac694792f51488ca2762 Author: Derrick Parkhurst

    <derrick.parkhurst@gmail.com> Date: Tue Aug 5 23:54:38 2014 -0500 my commit message commit ca82a6dff817ec66f44342007202690a93763949 Author: Derrick Parkhurst <derrick.parkhurst@gmail.com> Date: Mon Mar 17 21:52:11 2008 -0700 changed the version number commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 Author: Derrick Parkhurst <derrick.parkhurst@gmail.com> Date: Sat Mar 15 16:40:33 2008 -0700 removed unnecessary test code
  26. Creating a branch $ git checkout -b iss53

  27. Creating a branch $ git commit

  28. Multiple independent branches Feature Branch:

  29. Merging branches $ git checkout master $ git merge iss53

  30. git push $ git push {remote} {branch} Local Repository Origin

    Repository
  31. git pull $ git pull {remote} {branch} Local Repository Origin

    Repository
  32. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2
  33. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C1 C2 C1 C2 $ git checkout feature_branch $ git checkout feature_branch
  34. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C1 C2 $ git commit
  35. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C3 C1 C2 $ git push
  36. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C3 C1 C2 C3 $ git pull
  37. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C3 C1 C2 C3 C4 C5 $ git commit
  38. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C3 C4 C5 C1 C2 C3 C4 C5 $ git push
  39. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C4 C5 C1 C2 C3 C4 C5 C1 C2 C3 C4 C5 $ git pull
  40. Why don't I et a light saber?

  41. git amend $ git add somefle.rb $ git commit -m

    'third commit' C1 C2 C3 Feature Branch
  42. git amend $ git add somefle.rb $ git commit $

    git add forgotten.rb $ git commit --amend *** This creates a new commit *** C1 C2 C4 Feature Branch C3
  43. Sorry about the mess

  44. git log mess commit e36c9e65189b79fe9d3d60473a59a54de181fbc8 refactor based on code review

    commit 8b2716e0151ed6efaa1c0789b5e8920d9481fe5c make broken test pass commit cd55e5b78d1339927fef898f8f51f6ac688027bb fx typo commit 92efac1f814b2a02b554ac694792f51488ca2762 Added new feature
  45. Warning! Rewriting History Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C1 C2 $ git commit
  46. Warning! Rewriting History Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C3 C1 C2 $ git push
  47. Warning! Rewriting History Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C3 C1 C2 C3 $ git pull
  48. Warning! Rewriting History Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C4 C1 C2 C3 C1 C2 C3 $ git amend
  49. Warning! Rewriting History Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C4 C5 C1 C2 C3 C1 C2 C3 C6 $ git commit $ git commit
  50. Warning! Rewriting History Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C4 C5 C1 C2 C4 C5 C1 C2 C3 C6 $ git push --force
  51. Warning! Rewriting History Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C4 C5 C1 C2 C4 C5 C1 C2 C3 C6 $ git pull
  52. Don't try to rewrite public history

  53. I feel a great disturbance in the Force

  54. Train yourself to let go of everything you fear to

    loose
  55. git reflog --> git reflog • bf0715c HEAD@{0}: commit (amend):

    refactor based on code review • e36c9e6 HEAD@{1}: commit: refactor based on code review • 8b2716e HEAD@{2}: commit: make broken test pass • cd55e5b HEAD@{3}: commit: fix typo • 92efac1 HEAD@{4}: commit: my commit message
  56. We typically work on independent branches push --force with impunity

    Local Repository Origin Repository
  57. Work only on independent branches Use developer branches off of

    feature branches C1 C2 C3 Master C4 Feature C5 C6 C8 C10 Developer 1 Developer 2
  58. Attacking that battle station is not my idea of courage.

    It's more like, suicide.
  59. Quality commit messages Short (50 chars or less) summary of

    changes More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical Use the imperative present tense in these messages. In other words, use commands. Instead of "I added tests for" or "Adding tests for," use "Add tests for."
  60. Quality commits Do: – Logically separate content – Commit changes

    and tests together – Don't: – Commit fixups or refactorings Facilitates: – Code review – Reverting changes later in time – Testing and debugging
  61. Midi-chlorians $ git add -p $ git stash $ git

    rebase -i – Reword – Reorder – Combine – Split – Insert – Delete
  62. Intentional Git may the git --force be with you