Git je nejdůležitější nástroj každého vývojáře. Tady je vše, co potřebujete vědět.
Základy¶
git init
git clone URL
git add .
git commit -m “message”
git push origin main
Branches¶
git branch feature/login
git checkout feature/login
nebo: git checkout -b feature/login¶
git merge feature/login
git branch -d feature/login
Merge vs Rebase¶
Merge vytvoří merge commit, zachová historii. Rebase přepíše historii na lineární. Pravidlo: rebase lokální branches, merge sdílené.
Remote¶
git remote add origin URL
git fetch origin
git pull origin main
git push origin feature/login
Stash¶
git stash push -m “WIP”
git stash list
git stash pop
Tags¶
git tag -a v1.0.0 -m “Release 1.0”
git push origin –tags
Git Flow vs Trunk-based¶
- Git Flow: main, develop, feature/, release/, hotfix/ — pro release-based projekty
- Trunk-based: main + short-lived feature branches — pro CI/CD, doporučeno
.gitignore¶
node_modules/
.env
*.log
dist/
.DS_Store
Git Hooks¶
.husky/pre-commit¶
npm run lint
npm run test
Užitečné aliasy¶
[alias]
co = checkout
br = branch
st = status
lg = log –oneline –graph –all
Mastery¶
Git se naučíte praxí. Nebojte se experimentovat — reflog vás vždy zachrání.