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

A. Felipe Cabargas Madrid

December 12, 2019
Tweet

More Decks by A. Felipe Cabargas Madrid

Other Decks in Programming

Transcript

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

    don’t. I believe in you git config --global --add alias.st status git st
  2. At least use this Tips & Tricks - Day-2-Day git

    git log —-oneline —-graph
  3. 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
  4. 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
  5. What the hell happened yesterday? Tips & Tricks - Day-2-Day

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

    brew install git-extras https://github.com/tj/git-extras
  7. 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”
  8. 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
  9. 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
  10. 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
  11. 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.
  12. "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