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. 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
  2. 5.
  3. 6.

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

    git log —-oneline —-graph
  4. 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
  5. 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
  6. 12.

    What the hell happened yesterday? Tips & Tricks - Day-2-Day

    git git diff HEAD@{yesterday} Check usage guide at man pages for gitrevisions
  7. 13.

    Expand your git installation Tips & Tricks - Day-2-Day git

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