Miguel Costa
"A serious and good philosophical work could be written consisting entirely of jokes."
git switch <branch>
# same as git checkout <branch>
git restore
# git reset
# ex: git restore .
# ex.: git restore --staged <file-path>
# ex.: git restore --source <some-commit-hash> <file-path>
git log <branch> --graph
git log <branch> --oneline
git rebase <remote-branch>
# ex.: git rebase origin/develop
Not going well?
git rebase --abort
git remote show <remote_name>
# ex.: git remote show origin
# check HEAD branch field
and what's being tracked
Only the name of the default branch?
git remote show <remote_name> | grep 'HEAD branch' | cut -d' ' -f5
Undo/recover/move changes
Change state without losing what you have
Diagnose bugs
git commit -a -m "WIP"
git stash --all
git worktree add -b <BRANCH_NAME> <FOLDER> <TARGET_BRANCH>
git cherry-pick <some-commit-or-a-pointer-to-a-commit>
git checkout <branch_or_tag_or_commit> -- <path_to_file>
(Ref)Log that
git reflog
# or
git log -g --pretty=oneline
# only actions related to a branch
git reflog <BRANCH>
# e.g.: git reflog refs/remotes/origin/main
More details: Codeminer42's Engineering Blog
git log --since="2 weeks ago"
git log --since="1 month ago"
git log --since="2 years ago"
see https://git-scm.com/docs/git-log
git log -- <file-path>
see https://git-scm.com/docs/git-log
Git blame detects the commit with the last change in a line (could be indentation, refactoring, etc.)
Might not be what you want
(to find out where the bug came from)
Then, search for the intended change:
(in Vim) /something ("Enter" and 'n' or 'N' to navigate)
git log -p -m --follow --stat -- path/to/your/file
Why?
https://xkcd.com/1296/
Webpack
Commitlint + Conventional Commits
/** @type {import('@commitlint/types').UserConfig} */
export default {
extends: ["@commitlint/config-conventional"],
rules: {
"type-enum": [
2,
"always",
// for small-medium projects, I think these are enough!
["chore", "feat", "fix"]
],
},
};
// https://commitlint.js.org/guides/getting-started.html
// https://www.npmjs.com/package/@commitlint/config-conventional
commitlint.config.js
git show -s --format=%B <SOME_COMMIT_ID> | npx commitlint
Commitizen + Conventional Commits
npx commitizen init cz-conventional-changelog --save-dev --save-exact
// package.json
"scripts": {
// ou outra coisa
"commit-with-commitizen": "cz"
}
What should a README have?
What should a README (your first contact) have?
Introduction (title, summary, basic features. Should just be a paragraph and a list, at most)
Technical info (contacts and environments)
Project manager/owner
Code reviewers (e.g.: "Miguel Costa (@painatalman, front-end) environment URLs")
Environments (main, development, staging)
Project-related URLs (related projects, error tracking, etc.)
Get Started (prerequisites, installation, run project)
prerequisites (with versions)
steps to install
run project
start working on a feature
Development Workflow
branching model (link to Git and Operations)
common scenarios (testing methods, data importing)n
Project Architecture
Testing (test data, testing procedures, etc.)
Release and deployment: procedures deployment and release, with:
Deployment automation per environment
Post-merge procedure
Tag info
Development Scenarios
FAQ and Support
ONLY include project-specific content. Should mostly be links to detailed docs:
# Some whatever project
Official website to promote a resort and their services (golf, restaurants, real estate, etc.).
## Technical info
- Code reviewers: @Painatalman (front-end), @SomeOtherDood (back-end)
- Environments:
- production: <https://www.example.com/>
- Backoffice: <https://www.example.com/>
- Error tracking: <https://www.hiyoooo.com/>
- staging/development: <https://www.example.com/> (username: **username**, password: **password**)
- Backoffice: <https://www.example.com/>
- Error tracking: <https://www.example.com/>
- Stack: [Totally-not-MERN stack](...)
## Get started
See [this stack's "Get Started" section](...), noting that:
- The `things_templates` folder goes to `project/project-home`
- To load data via a MySQL dump, run (with the containers running):
```bash
docker-compose exec -T db mysql --host localhost --port 3310 -pqwerty -u root this_db < this_db.sql
```
## Workflow
For information on how to work on features and fixes, check respective stack's [Development Workflow](...)
## Development scenarios
See this stack's [Development scenarios](...), with the following additions/exceptions:
### Access backoffice
When accessing a backoffice, be sure to **log in using your e-mail** and not your username.
### Create backoffice user
1. From the project folder, run:
```bash
docker-compose run --rm web python manage.py createsuperuser
```
2. add desired credentials when prompted:
1. set username
2. set email address - **important** due to custom implementations, **this field is required**, unlike most projects using `django-admin`
3. set password twice
4. access the [backoffice](`<http://localhost:8000/admin>`)
5. set credentials
6. username field matches email you inserted
7. password, as the name implies, matches the prompted password
### Update booking e-mails
Booking e-mails use MJML and a custom setup detailed in [Notification Service's Development Scenarios](...)
### Other scenarios
For overall scenarios, check respective stack's ["Development scenarios" section](...)
Consider:
Pull Requests — Why?
Pull/Merge Requests — Examples
Pull/Merge Requests — Templates
<!--
TITLE: "Feature/???"
NOTE: Remove empty sections
-->
## Changed
<!-- Features that impact the app's behaviour or close issues. E.g.:
- improved styles for form fields (closes #123);
- translated copy for subscription page.
-->
## Chores
<!-- Changes that don't impact the app's behaviour. E.g.:
- added environments to README;
- added tests to component.
-->
## How to test
<!-- numbered steps on how to test the new feature. E.g.:
1. log in with username and password...
2. go to page...
-->
## Post-merge
<!-- Additional steps on what to do when merged. E.g.:
1. release to staging/production
1. run migrations in target environment (run "run migrations" in CI),
2. disable this page via backoffice
3. run "how to test" from !131
-->
<!--
TITLE: Release/Staging, Release/Production, or Release/<git-tag> (e.g.: "Release/v1.1.0")
ITEM FORMAT:
- Related MR link (! with MR number)
- link to the related task, if possible
- group MRs associated with same task (add description, if appropriate). E.g.:
- !123 ([task](http://www.example.com))
- !131, !141 (login form updates, see [task](http://www.example.com))
NOTES:
- check "Release" section in README for release info
- check related MR Post-merge sections
- remove empty sections
-->
## Fixed
<!-- for MRs named "Fix/???" not associated with a new feature -->
## Changed
<!-- for MRs named "Feature/???" -->
## Chores or Redundant
<!-- for MRs named "Chore/???", or redundant MRs like hotfixes (already in production) -->
## Post-merge
<!-- Additional steps on what to do when merged. E.g.:
1. release to staging/production
1. run migrations in target environment (run "run migrations" in CI),
2. disable this page via backoffice
3. run "how to test" from !131
-->
.gitlab/merge_request_templates/Release.md
Pull/Merge Requests — Templates
Issues — Templates
Issues & Pull Requests — Code Review
Should you? Yes, if...
Tips for
Authors
Tips for
Reviewers
Release Changes
Ideally, only add "source code" files (subject to trackable changes).
Have a consistent workflow (that allows collaboration without unneeded complexity).
Not a metro map
Not a Git project
main commits are tagged, can have support branches
minor release = hotfix
feature: from develop to develop
release branch goes to both master and develop
release/v1.0.1
release/v.0.1.1
feature/hair-color
https://www.alexhyett.com/git-flow-github-flow/
that made me
more aware of what I'm doing
git status
git fetch --prune
git pull
git branch --merged | grep -v "*"|awk '{print "git branch -d " $1}'|bash
git commit ...
# forgot to add something, or wants to replace commit message
git commit ... --amend
git push <remote_probably_origin> <branch> --force-with-lease
git push <remote_probably_origin> <branch> --force-with-lease
git add -p ...
git checkout -p ...
git reset -p ...
git log -p ...
git rebase -i <remote_branch>
# example: git rebase -i origin/develop
By Miguel Costa
In this presentation, I'd like to share with you some interesting stuff about system versioning with GIT.