Git beyond basics

25
Senior Software Engineer Kalpa Welivitigoda Git | Beyond Basics

Transcript of Git beyond basics

Page 1: Git   beyond basics

Senior Software EngineerKalpa Welivitigoda

Git | Beyond Basics

Page 2: Git   beyond basics

**

๏ Initializing a git repository

๏ Adding files

๏ Committing

๏ Adding remotes

๏ Push/Pull

๏ Status

What we know already

Page 3: Git   beyond basics

**

WSO2/product-as john/product-as

John’s local filesystem

product-as

Fork

Clone(origin)

Remote(upstream)

Page 4: Git   beyond basics

**

We are no alone!

WSO2/product-as bill/product-as

john/product-asJohn’s local filesystem

product-as

bob/product-as

Bill’s local filesystem

product-as

Bob’s local filesystem

product-as

Page 5: Git   beyond basics

**

Developing a feature

Page 6: Git   beyond basics

**

Keep up with the changes...

Page 7: Git   beyond basics

**

MergeVs.

Rebase

Page 8: Git   beyond basics

**

git merge

$ git checkout feature $ git merge master

๏ Non destructive mechanism

๏ Additional commit

Page 9: Git   beyond basics

**

git rebase

$ git checkout feature $ git rebase master

๏ Cleaner commit history

๏ Rewrites the history!!!!

Page 10: Git   beyond basics

**

๏ Very powerful

๏ Clean the commit history before merging to master

branch

$ git rebase -i HEAD~10

Interactive rebase

# Commands:p, pick = use commitr, reword = use commit, but edit the commit messagee, edit = use commit, but stop for amendings, squash = use commit, but meld into previous commitf, fixup = like "squash", but discard this commit's log messagex, exec = run command (the rest of the line) using shelld, drop = remove commit

Page 11: Git   beyond basics

**

Split commits | Demo

Page 12: Git   beyond basics

**

git stash

๏ A stack of uncommitted changes

๏ Tracks modified files and staged changes

๏ Useful when switching between branches

Page 13: Git   beyond basics

**

$ 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}}

Page 14: Git   beyond basics

**

Selective stashing | Demo

Page 15: Git   beyond basics

**

$ git log --oneline$ git log --decorate$ git log --stat$ git log -- graph --oneline --decorate $ git shortlog

$ gitk

git log

Log formatting

Page 16: Git   beyond basics

**

$ 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

Page 17: Git   beyond basics

**

$ git config --global alias.lo "log --oneline"

$ git lo

git alias

Page 18: Git   beyond basics

**

$ git checkout feature$ git cherry-pick 5a63064

git cherry-pick

๏ It’s a new commit !!!!

Page 19: Git   beyond basics

**

$ git reflog

git reflog

๏ git log shows commits in ancestor order

๏ Reflog shows in the order you last referenced the

commits

Page 20: Git   beyond basics

**

$ 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

Page 21: Git   beyond basics

**

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)

Page 22: Git   beyond basics

**

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

Page 23: Git   beyond basics

**

Reference

๏ https://www.atlassian.com/git/tutorials/advanced-ov

erview

๏ http://chris.beams.io/posts/git-commit/

๏ https://git-scm.com/doc

Page 24: Git   beyond basics

**

Questions ?

Page 25: Git   beyond basics

**

Thank You !