such git

much commands

wow

Objective:

Best Ways to Use Git

its own way to work with it

so let's start with the basic

GIT BASICS

STAGES

Blob

doc

Tree

Blob

Blob

commit

1496fa3

a4b627e

e05add4

e019271

c57ec75

SHA-1

commit is a photo

  • Hash to Git Tree
  • Comment
  • Commit Author
  • Parent Hash!

why is this important?

rebase
&
merge

rebase

$ git checkout master
$ git log --oneline
48f1836 bring sugar
24b85a2 prepare coffee
c460145 start fika
$ git checkout cinnamon-rolls
$ git log --oneline
a58ebc7 score
8b7b9a3 insert cinnamon-rolls
1c2a4f2 heat oven
c460145 start fika

branch cinnamon-rolls

branch master

older

newer

$ git checkout cinnamon-rolls
$ git checkout rebase master
$ git log --oneline
48f1836 bring sugar
24b85a2 prepare coffee
c460145 Start fika
$ git log --one-line
a58ebc7 score
8b7b9a3 insert cinnamon-rolls
1c2a4f2 heat oven
c460145 start fika

COMMON PARENT

branch cinnamon-rolls

branch master

$ git checkout cinnamon-rolls
$ git checkout rebase master
$ git log --oneline
48f1836 bring sugar
24b85a2 prepare coffee
c460145 Start fika
$ git log --oneline
48f1836 bring sugar
24b85a2 prepare coffee
c460145 Start fika

branch cinnamon-rolls

branch master

??? score
??? insert cinnamon-buns
??? heat oven

MOVE TO HEAD OF MASTER

$ git checkout cinnamon-rolls
$ git checkout rebase master
$ git log --oneline
48f1836 bring sugar
24b85a2 prepare coffee
c460145 Start fika
$ git log --oneline
b0bc9a8 heat oven
48f1836 bring sugar
24b85a2 prepare coffee
c460145 Start fika

branch cinnamon-rolls

branch master

??? score
??? insert cinnamon-buns

REPLAYS EACH COMMIT

*

$ git checkout cinnamon-rolls
$ git checkout rebase master
$ git log --oneline
48f1836 bring sugar
24b85a2 prepare coffee
c460145 Start fika
$ git log --oneline
3db5776 score
1ec3a7d insert cinnamon-buns
b0bc9a8 heat oven
48f1836 bring sugar
24b85a2 prepare coffee
c460145 Start fika

branch cinnamon-rolls

branch master

*

*

*

destructive

it changes the git tree

  • Only do it to non-shared branches
  • More than just using for nice tree

merge

$ git checkout master
$ git log --oneline
48f1836 bring sugar
24b85a2 prepare coffee
c460145 start fika
$ git checkout cinnamon-rolls
$ git log --oneline
a58ebc7 score
8b7b9a3 insert cinnamon-rolls
1c2a4f2 heat oven
c460145 start fika

branch  cinnamon-rolls

branch master

older

newer

$ git checkout master
$ git log --oneline
48f1836 bring sugar
24b85a2 prepare coffee
c460145 start fika
$ git checkout cinnamon-rolls
$ git log --oneline
a58ebc7 score
8b7b9a3 insert cinnamon-rolls
1c2a4f2 heat oven
c460145 start fika

branch  cinnamon-rolls

branch master

$ git checkout rebase master
$ git merge cinnamon-rolls
$ git checkout master
$ git log --oneline
a9c27be Merge branch 'cinnamon-rolls' into 'master'
a58ebc7 score
8b7b9a3 insert cinnamon-rolls
1c2a4f2 heat oven
48f1836 bring sugar
24b85a2 prepare coffee
c460145 start fika
$ git checkout cinnamon-rolls
$ git log --oneline
a58ebc7 score
8b7b9a3 insert cinnamon-rolls
1c2a4f2 heat oven
c460145 start fika

branch  cinnamon-rolls

branch master

$ git checkout rebase master
$ git merge cinnamon-rolls

resolve conflicts

  • New Commit with Resolution
  • Have two parents

which one to use?

rebase your branches often

rebase your branches often

  • Cleaner history
  • Easier to resolve conflicts

merge new features

  • Only marker of points in time
    • In conjuction with good rebases

TIPS

COMMIT EARLY
&
COMMIT OFTEN

moving files

  • Move Files
  • Commit
  • Modify!
# Check the history identifying even moving around!
$ git log --follow FILE

Improve your branch before pushing

  • interactive rebase!
# Change your commits interactivelly
$ git checkout your-branch
$ git rebase -i master

Search inside your repo

# Search inside the context indexed
$ git grep "what to search"
# Search for commit with given text
$ git log --grep="text"
# Search for commit of a given text
$ git log -S "Text"
# Search based on time
$ git log --since=1.week.ago --until=today

use git aliases

& our dotfiles project ;)

https://stash.int.klarna.net/projects/RISK/repos/risk-dotfiles/browse/git/gitconfig.symlink.template

play with git!

DON'T BE AFRAID

use the tools!

thanks ;]

References

  • http://git-scm.com/book
  • http://think-like-a-git.net/
  • http://www.gitguys.com/

 https://www.atlassian.com/git/articles/git-team-workflows-merge-or-rebase/

  • das interwebs

such-git-much-commands

By Caesar Ralf Franz Hoppen

such-git-much-commands

Best Practices while using git

  • 1,525