Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Untangling git

Untangling git

Tips & Tricks for daily git usage + some tips on conflict resolution

25b46534e22c85a4d028403d83fcc6e0?s=128

A. Felipe Cabargas Madrid

December 12, 2019
Tweet

Transcript

  1. Untangling Git 12.12.2019 - Felipe Cabargas

  2. A.K.A. the stupid content-tracker

  3. Day to Day Git Tips & Tricks

  4. Tips & Tricks - Day-2-Day git Create aliases … or

    don’t. I believe in you git config --global --add alias.st status git st
  5. A better log == A happier you git log Tips

    & Tricks - Day-2-Day git
  6. At least use this Tips & Tricks - Day-2-Day git

    git log —-oneline —-graph
  7. Or go over the top like this Tips & Tricks

    - Day-2-Day git git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
  8. Maybe just install tig Tips & Tricks - Day-2-Day git

    tig
  9. Maybe just install tig Tips & Tricks - Day-2-Day git

    tig show HEAD tig blame etc
  10. I’m sure I pushed this… Tips & Tricks - Day-2-Day

    git git cherry -v
  11. Never force-push… OK, maybe sometimes but nicer Tips & Tricks

    - Day-2-Day git git push --force-with-lease This will only push if the remote branch hasn’t been updated
  12. What the hell happened yesterday? Tips & Tricks - Day-2-Day

    git git diff HEAD@{yesterday} Check usage guide at man pages for gitrevisions
  13. Expand your git installation Tips & Tricks - Day-2-Day git

    brew install git-extras https://github.com/tj/git-extras
  14. Conflict Resolution Tips & Tricks

  15. Feature Branching is messy sometimes master dev-a/feature-a dev-b/feature-b Tips &

    Tricks - Conflict Resolution
  16. Ours/Theirs Tips & Tricks - Day-2-Day git git merge feature-branch

    CONFLICT ON file.rb git checkout —-ours file.rb git add file.rb git commit -m “Our code is so much better”
  17. Tips & Tricks - Conflict Resolution Been here? user $

    ~/project git:(master) git status On branch master Your branch is up to date with ‘origin/master’ You have unmerged paths. (fix conflicts and run “git commit”) (use “git merge —-abort” to abort merge) Unmerged paths: (use “git add <file>..." to mark resolution) both modified: file.rb both modified: another-file.rb user $ ~/project git:(master) git add . user $ ~/project git:(master) git commit user $ ~/project git:(master) git status On branch master Your branch is up to date with ‘origin/master’ You have unmerged paths. (fix conflicts and run “git commit”) (use “git merge —-abort” to abort merge) Unmerged paths: (use “git add <file>..." to mark resolution) both modified: file.rb both modified: another-file.rb
  18. git-rerere to the rescue git config rerere.enabled true git global

    config rerere.enabled true rerere stands for reuse recorded resolution Tips & Tricks - Conflict Resolution
  19. Tips & Tricks - Conflict Resolution user $ ~/project git:(master)

    git status On branch master Your branch is up to date with ‘origin/master’ You have unmerged paths. (fix conflicts and run “git commit”) (use “git merge —-abort” to abort merge) Unmerged paths: (use “git add <file>..." to mark resolution) both modified: file.rb both modified: another-file.rb You will still get this message but if you diff the file you will see that the resolution was already applied. git-rerere to the rescue
  20. Tips & Tricks - Conflict Resolution How to avoid Merge

    conflicts - Check your PR in GitHub. If Merging is blocked against master, fix if then merge with staging. - Keep your PR updated against master. - rebase until you reach a deployable state. - After you reach staging, merge master to your feature-branch periodically. - Pull staging always before merging. - If during your conflict resolution, someone else pushed into staging, undo your merge and do it again. - Whenever possible, fix conflicts in your feature-branch then merge. - Avoid merging a branch onto itself at all costs. - Avoid merging onto a broken environment. Check Jenkins first.
  21. "It is easy to shoot your foot off with git,

    but (is) also easy to revert to a previous foot and merge it with your current leg.” Jack William Bell
  22. Gracias! Tak!