GIT

for beginners++

Krzysztof Szumny - noisy

git tips

 

  • don't use fancy gui programs for git - use console!
  • explicit over implicit
  • learn how to work with multiple repositories
  • draw your branches!
    • git log --decorate
  • be obsessed about your git status
    • customized prompt
  • Basic


     

  • Advanced

git prompt

Real live examples:

git log

git log --decorate --graph --oneline

git log

git log --decorate

git log --decorate --graph 

the power of -p

Multiple repositories

local and remote

Typical tasks which requires

counterintuitive solutions

  • Modifying a commit
  • Deleting a branch
  • Deleting a commit

Modifying a commit

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

Delete a branch

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 interactive
  • 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

Made with Slides.com