Tom's wiki

Git

The version control system.

Learn

Best practices

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:

Config

Default location:

Hooks

https://githooks.com

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:

Conventional commits:

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.