1 of 38

Matouš

Czerner

How to Love Git

Developer

2 of 38

Matouš Czerner

www.shopsys.com

Develop Faster. Stay Innovative.

matous.czerner@shopsys.com

Developer of Shopsys Framework

Docker fan

3 of 38

Why am I even talking about Git?

www.shopsys.com

Develop Faster. Stay Innovative.

4 of 38

5 of 38

What is causing this?

  • Master gets updated and my feature branch is behind

  • I want my feature branch to be up to date, so i decide to update my branch to origin with:
  • merge master to feature branch

www.shopsys.com

Develop Faster. Stay Innovative.

6 of 38

www.shopsys.com

Develop Faster. Stay Innovative.

7 of 38

www.shopsys.com

Develop Faster. Stay Innovative.

8 of 38

www.shopsys.com

Develop Faster. Stay Innovative.

9 of 38

www.shopsys.com

Develop Faster. Stay Innovative.

10 of 38

www.shopsys.com

Develop Faster. Stay Innovative.

11 of 38

12 of 38

Git Rebase

www.shopsys.com

Develop Faster. Stay Innovative.

13 of 38

  • Usable if base branch (master) is forward of your feature branch

  • Tries to apply all changes done in feature branch onto target branch

www.shopsys.com

Develop Faster. Stay Innovative.

14 of 38

www.shopsys.com

Develop Faster. Stay Innovative.

15 of 38

git rebase origin/master

www.shopsys.com

Develop Faster. Stay Innovative.

16 of 38

www.shopsys.com

Develop Faster. Stay Innovative.

17 of 38

www.shopsys.com

Develop Faster. Stay Innovative.

18 of 38

What is the difference?

www.shopsys.com

Develop Faster. Stay Innovative.

19 of 38

With git rebase

Without git rebase

www.shopsys.com

Develop Faster. Stay Innovative.

20 of 38

Conclusion

  • Instead of merging origin changes into branch, try to rebase feature branch onto origin

  • History is much cleaner

  • We are not creating guitar hero!!

www.shopsys.com

Develop Faster. Stay Innovative.

21 of 38

But wait. Can we do more with it?

www.shopsys.com

Develop Faster. Stay Innovative.

22 of 38

Daily code reviews and fixes

www.shopsys.com

Develop Faster. Stay Innovative.

23 of 38

3cc0f07 CHANGELOG informations added

ca7f5d9 greatest contribution ever

www.shopsys.com

Develop Faster. Stay Innovative.

24 of 38

Code Review time

www.shopsys.com

Develop Faster. Stay Innovative.

25 of 38

7fa3a66 fixed code and stuff

b328677 fixed CHANGELOG

3cc0f07 CHANGELOG informations added

ca7f5d9 greatest contribution ever

www.shopsys.com

Develop Faster. Stay Innovative.

26 of 38

git rebase --interactive origin/master

www.shopsys.com

Develop Faster. Stay Innovative.

27 of 38

rebase interactive

  • Perform rebase, but lets you change the commits themselves

  • Lets you change commit messages, order of commits, or squash some changes together

www.shopsys.com

Develop Faster. Stay Innovative.

28 of 38

pick 7fa3a66 fixed code and stuff

pick b328677 fixed CHANGELOG

pick 3cc0f07 CHANGELOG informations..

pick ca7f5d9 greatest contribution ever

www.shopsys.com

Develop Faster. Stay Innovative.

29 of 38

fixup b328677 fixed CHANGELOG

pick 3cc0f07 CHANGELOG informations..

fixup 7fa3a66 fixed code and stuff

pick ca7f5d9 greatest contribution ever

www.shopsys.com

Develop Faster. Stay Innovative.

30 of 38

3cc0f07 CHANGELOG informations added

ca7f5d9 greatest contribution ever

www.shopsys.com

Develop Faster. Stay Innovative.

31 of 38

Conclusion

  • You can change your commits, and the content inside it

  • Commits are not permanent and you can change them as many as you like

www.shopsys.com

Develop Faster. Stay Innovative.

32 of 38

But what if I F*CK up and my changes get lost?

www.shopsys.com

Develop Faster. Stay Innovative.

33 of 38

Reflog gots your back.

www.shopsys.com

Develop Faster. Stay Innovative.

34 of 38

git reflog

  • Git keeps history of every move you make in git

  • You can always reset your worktree to some functional revision in past

  • Nothing is permanent, everything in git is revertable

www.shopsys.com

Develop Faster. Stay Innovative.

35 of 38

HEAD@{0}: rebase -i (finish): returning to my-greatest-contribution

HEAD@{1}: rebase -i (fixup): Updated readme, cuz it makes sense

HEAD@{2}: rebase -i (pick): Updated readme, cuz it makes sense

HEAD@{3}: rebase -i (fixup): My flawless contributions

HEAD@{4}: rebase -i (start): checkout origin/master

HEAD@{5}: commit: Fixed code and stuff

www.shopsys.com

Develop Faster. Stay Innovative.

36 of 38

git reset --hard HEAD@{5}

www.shopsys.com

Develop Faster. Stay Innovative.

37 of 38

Git is your friend.

www.shopsys.com

Develop Faster. Stay Innovative.

38 of 38

Matouš Czerner

www.shopsys.com

Develop Faster. Stay Innovative.