Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Git beyond basics

278 views

Published on

In this presentation, I go through the basic flow of using git, some of the git commands with their advanced usages and at the latter part I discuss the best practices in using git.

Published in: Software
  • Login to see the comments

Git beyond basics

  1. 1. Senior Software Engineer Kalpa Welivitigoda Git | Beyond Basics
  2. 2. ** ๏ Initializing a git repository ๏ Adding files ๏ Committing ๏ Adding remotes ๏ Push/Pull ๏ Status What we know already
  3. 3. ** WSO2/product-as john/product-as John’s local filesystem product-as Fork Clone (origin) Remote (upstream)
  4. 4. * * We are no alone! WSO2/product-as bill/product-as john/product-as John’s local filesystem product-as bob/product-as Bill’s local filesystem product-as Bob’s local filesystem product-as
  5. 5. * * Developing a feature
  6. 6. * * Keep up with the changes...
  7. 7. * * Merge Vs. Rebase
  8. 8. * * git merge $ git checkout feature $ git merge master ๏ Non destructive mechanism ๏ Additional commit
  9. 9. * * git rebase $ git checkout feature $ git rebase master ๏ Cleaner commit history ๏ Rewrites the history!!!!
  10. 10. ** ๏ Very powerful ๏ Clean the commit history before merging to master branch $ git rebase -i HEAD~10 Interactive rebase # Commands: p, pick = use commit r, reword = use commit, but edit the commit message e, edit = use commit, but stop for amending s, squash = use commit, but meld into previous commit f, fixup = like "squash", but discard this commit's log message x, exec = run command (the rest of the line) using shell d, drop = remove commit
  11. 11. ** Split commits | Demo
  12. 12. * * git stash ๏ A stack of uncommitted changes ๏ Tracks modified files and staged changes ๏ Useful when switching between branches
  13. 13. ** $ git stash $ git stash save stash1 git stash... $ git stash list $ git stash apply $ git stash apply stash@{1} $ git stash drop $ git stash pop $ git stash -p $ git checkout stash@{n} -- {{file_path}}
  14. 14. ** Selective stashing | Demo
  15. 15. ** $ git log --oneline $ git log --decorate $ git log --stat $ git log -- graph --oneline --decorate $ git shortlog $ gitk git log Log formatting
  16. 16. ** $ git log -3 $ git log --after="2016-09-01" $ git log --after="yesterday" $ git log --after="1 week ago" $ git log --author="John|Mary" $ git log --grep="WSAS" $ git log -- pom.xml $ git log -S "maven-deploy-plugin" $ git log --no-merges $ git log -- merges $ git log <since>...<until> git log... Log filtering
  17. 17. ** $ git config --global alias.lo "log --oneline" $ git lo git alias
  18. 18. ** $ git checkout feature $ git cherry-pick 5a63064 git cherry-pick ๏ It’s a new commit !!!!
  19. 19. ** $ git reflog git reflog ๏ git log shows commits in ancestor order ๏ Reflog shows in the order you last referenced the commits
  20. 20. ** $ git bisect start $ git bisect good <good commit hash> $ git bisect bad <bad commit hash> $ git bisect reset git bisect ๏ Used to find the commit that introduced a bug/fix ๏ Do a binary search of the commits
  21. 21. ** Git best practices ๏ Develop features in feature branches ๏ Commit often, perfect later, publish once ๏ Never change published history (it is possible with push -f, but never ever do it) ๏ Keep your git tree clean (git pull upstream master --rebase)
  22. 22. ** Git best practices... ๏ A commit message has a subject and a body. ๏ Make the commit subject imperative ๏ Link to the JIRA/Git Issue ID ๏ WSAS-1169 : <commit subject> ๏ Resolves #21
  23. 23. ** Reference ๏ https://www.atlassian.com/git/tutorials/advanced- overview ๏ http://chris.beams.io/posts/git-commit/ ๏ https://git-scm.com/doc
  24. 24. ** Questions ?
  25. 25. ** Thank You !

×