tags:
- git
permalink: what-is-git
title: What is Git?
date created: Friday, October 20th 2023, 9:44:07 pm
date modified: Tuesday, May 6th 2025, 3:36:36 pm
Git is version control software. Use it to track changes to files and revert mistakes. Think of it like a Save Progress button.
List your config.
git config -l
Configure your name and email.
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"
Your config is saved in ~/.gitconfig
. Edit it with a text editor.
open ~/.gitconfig
Configure VS Code as merge and diff tools.
# Configure VS Code as git mergetool
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait --merge $REMOTE $LOCAL $BASE $MERGED'
git config --global mergetool.keepBackup false
# Configure VS Code as git difftool
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
List available Git tags.
git tag
Push tag to a remote, e.g., origin
.
git push origin ${TAG}
main
branch is the one source of truth. Feature branches branch from main
.git rebase
instead of git merge
to enforce linear history. This makes commits easier to group and track.Use Commitizen to write properly formatted commit messages: cz c
Use Commitizen with a semantic release tool ensures that your code has a unique version number. The version number is based on Git history.
Write commit messages to finish the sentence, "This commit will..."
Some examples:
Push a branch from one remote (i.e., origin
) to another, preserving its name.
git push "${REMOTE_NAME}" "origin/${BRANCH_HAME}:refs/heads/${BRANCH_HAME}"
Get details about a commit, including its parent, the previous commit. This is useful for rebasing or working with Commitizen.
git show "${COMMIT_HASH}"
Get only the parent commit of a commit.
git rev-parse "${COMMIT_HASH}^"
Free up disk space by collecting garbage and compressing all repositories under the given directory DIR
.
find "${DIR}" -type d -name ".git" -execdir git gc \;
Revert commits from the HEAD to a past commit.
git revert --no-commit ${COMMIT_HASH+1}..HEAD
git commit -m 'Revert to ${COMMIT_HASH}'