Zen of GIT

Krzysztof Szumny
STX Next - Wrocław, 10.12.2015

git tips

 

  • explicit over implicit
  • learn how to work with multiple repositories
  • draw your branches!
    • git log --decorate
  • be obsessed about your git status
    • customized prompt
    • power of -p switch
  • always be sure, that you have a backup
    • branch name is like a sticker
    • git new-workdir
  • Basic


     

  • Advanced

git prompt

git log

git log --decorate

git log --decorate --graph

git log --decorate --graph --oneline

Real live examples:

git log

power of -p

live demo

Backup

Multiple repositories

local and remote

Push a branch

git push <repo> <remote_branch>
git push origin feature-8

git push <repo> <branch>:<remote_branch>
git push origin feature-8:feature-8

git push <repo> <branch>:<remote_branch>
git push origin feature-8~1:feature-8

Deleting a branch with push

git push <repo> <branch>:<remote_branch>

git push origin :feature-8

git push <repo> --delete <remote_branch>

git push origin --delete feature-8

Reset a branch/delete a commit

git reset --hard <hash/branch>

git reset --hard HEAD~1

git reset --hard origin/feature-8

Rebase

  • rebase - what is that?
  • why rebase is needed
  • lets imagine that there is no rebase...
    • how to manually achieve this same result
  • How git know what commits need to be rebased
  • git rebase --onto

When we need rebase?

1. New changes were pushed to base branch

When we need rebase?

2. when we want to delete a commit, which is not the last

When we need rebase?

3. commits are on wrong branch

*this is more difficult rebase, requires --onto

How rebasing works

rebase is like automated version of cherry-pick

so let's explain very quickly how git cherry-pick works...

$ git cherry-pick feature-7~1

How rebasing works

$ git rebase master


Lets take a look on git rebase --interactive
demo: https://asciinema.org/a/bgau9swvdqz2jqx7fxyjq57tb

How git knows which commits needs to be rebased

$ git merge-base master feature-8
C

git merge-base <branch> <branch>

branch from another branch

# being on feature-9
git rebase feature-8
# being on feature-8
git rebase master
# being on feature-9
git rebase feature-8   #???
# being on feature-9
git rebase --onto feature-8 feature-9~3 feature-9

Upcoming scheduled livestream:

Lecture: Git for beginners++

  • Duration: 45 minutes + Q&A session
  • Language: English
  • When?

Q&A

Zen of Git

By noisy

Zen of Git

  • 1,681