Git
The version control system.
Learn
- Common fuckups: https://ohshitgit.com
- Rebase in depth: https://git-rebase.io
- Email-driven workflow: https://git-send-email.io
Best practices
- Prefer rebase to merge
- Squash commits on merge
- Delete branches after merge
HEAD
HEAD
is a pointer to the current position in the git history.
It typically points to a branch, but may also point to a specific commit (a detached HEAD
state).
The current HEAD
target can be found in the .git/HEAD
file.
Use ~
(linear history) or ^
(non-linear history) to reference the ancestors of a commit:
HEAD~0
: the commit itselfHEAD~1
: the parent of the commitHEAD~2
: the grandparent of the commit
Config
Default location:
gitconfig
:$XDG_CONFIG_HOME/git/config
or$HOME/.gitconfig
gitignore
:$XDG_CONFIG_HOME/git/ignore
(can be customized withcore.excludesFile
)
Hooks
The default hooks directory is .git/hooks
.
It can be changed with core.hooksPath
.
The most common hook is pre-commit
.
It can be bypassed with git commit --no-verify
.
Workflow
Versioning:
- SemVer:
MAJOR.MINOR.PATCH
; use it, don't reinvent the wheel. - ZeroVer: same, but
MAJOR
is always zero, so no need to worry about backward compatibility.
- feat: new feature (bump
MINOR
) - fix: new patch (bump
PATCH
) - dev: refactoring
- docs: docs update
- test: tests update
- chore: CI, deps, etc
Commit signing
Git does not authenticate the author of a commit, so anyone can push commits with any email. If you care about your digital identity being abused, you should sign your commits.
See also:
How to
Get the latest tag:
git describe --tags --abbrev=0
Get the first commit:
git rev-list --max-parents=0 HEAD
Reset (softly) all commits:
git update-ref -d HEAD
Rebase (interactively) starting from the first commit:
git rebase --root --interactive --committer-date-is-author-date
✏️ Note
Use--committer-date-is-author-date
to preserve the original commit dates. The author date says when the commit was originally made. The commit date gets changed every time the commit is modified.