Skip to content

Instantly share code, notes, and snippets.

@mz0
Last active September 6, 2019 08:31
Show Gist options
  • Save mz0/ccc40522051c3d13496c357f3a67dec9 to your computer and use it in GitHub Desktop.
Save mz0/ccc40522051c3d13496c357f3a67dec9 to your computer and use it in GitHub Desktop.
Git crash-course plan

Pragmatic Git

What Git is not? It's not SVN, it's not a lifesaver, it's not a backup, it's not an enigma, it's not a nightmare.

Just the right combination of tiny fractions of all of the above done in the most straightforward way :)

Well I lied you, it's borderline anti-SVN (The author introduces Git to Google devs on May 03, 2007)

Alternative approach

sarcastic Git intro

Git building blocks

  • what is a hash? is MD5 broken?
  • who is DAG? Where do Mercle trees grow?
  • blob, tree, commit
  • branch, tag, index

Basic git workflow (in an existing repo):

  • git fetch
  • git pull
  • git add # what's Git index btw?
  • git reset # oops, i've added smth. unwanted!
  • git diff
  • git diff --stat
  • git diff HEAD
  • git commit
  • git push (if you have privs!)

Git log is for humans, read it, find out what's good, what's bad.

  • git log --oneline -10
  • git show --stat d7970a4d
  • git diff --stat .. ..
  • Respect logs, separate code / formatting commits
  • what does your commit look like on Github? in IDEA?
  • 50/72 rule

Do your stuff in a sandbox, merge when done, cleanup afterwards.

  • git checkout -b mycrap # if you are cautious enough
  • git stash # otherwise (git stash list; git stash pop)
  • git stash -b mycrap
  • git add / git commit
  • git checkout
  • git merge mycrap
  • <fix conflicts, commit>
  • git branch -d mycrap

Fix early

  • git commit --amend
  • if you are late - seek seniors' help! But do this, and do it soon!

Avoid pointless merges:

  • it's plain ugly
* d7970a4d (HEAD -> eminer35, origin/exactpro/config_miner_v35) add scripts and docs for token_bootstrapper_light
* 94c40d76 OSX 0.0.0.0 fix
* 51560a54 cenm-kostroma oracle
* 50253a08 cenm-kostroma oracle
* 5be55679 oracle for CENM
* 29af68d2 cenm-kostroma
* c916cba9 cenm-kostroma
* 8ab81c07 cenm-kostroma
* f83759cd cenm-kostroma
* b26fd4c6 cenm-kostroma
* ec4fd9bc cenm-kostroma
* f5e5a929 cenm-kostroma
* 2d4b89f5 cenm-kostroma
* b3d9bc28 configure node logging
*   70a64f59 Merge branch 'exactpro/config_miner_v35' of https://github.com/corda/behave into exactpro/config_miner_v35
|\  
| * caff262c use ENT-4.2-RC77 name, ENTERPRISE/4.2-RC77/ folder
* | 6d92d38e ha proxy test
|/  
* 110751c2 stop ha proxy
* 43671a15 cenm-signer
* 2abc8b59 cenm-signer

git fetch  # before commit
git pull --rebase # if there're changes
git commit
git push

Correcting mistaeks

  • Bad messages; reoder, squash commits.
git rebase -i <good-commit>

Advanced topics

  • alias gl1='git log --oneline'
  • tags
  • tracking rebased branch (secret link)
  • tracking renamed files - TODO
  • git blame
@mz0
Copy link
Author

mz0 commented Sep 6, 2019

This is NOT ok!

commit-message-KO

This is OK

commit-message-OK

Building blocks

The story goes that the very first beta Google server was made of Duplo bricks cause cheaper generics were not rigid enough ;)

pic source
Real Google-1999 and story
side view

Git building blocks

history-is-a-DAG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment