Kjell

Git

About git

Why git

Man

A built-in manual.

man git-add
man git-commit
man git-"command"

Install git

Git is installed when you install the xcode command line tools.

xcode-select --install

Username & email

git config --add --global user.name "username"
git config --add --global user.email "email@adress"
git config --add --global core.editor "nano"

git config --get user.name
git config --get user.email
git config --get core.editor

Create a new git-repo

git init

Oops..

You wouldnt be the first to accidentally put its whole documents’ directory under source control.

Checking status

git status

Checking diff

git diff
git diff --staged

Staging files

git add "path-to-file | pattern"
git add .
git add -A .

Committing files

git commit
git commit -m "My commit message"

Tracking & committing files

You local repo consists of three “trees” maintained by git:

  1. Working directory: holds the actual files.
  2. Index: acts as a staging area.
  3. HEAD: points to the last commit you’ve made.

Add

Commit

Untracked, staged, and tracked files

Untracked files

Indexed / staged

Tracked

Undo changes after staging

git restore --staged hello.txt
git restore hello.txt

Logging

decorate: puts branches / HEAD in the commit logs so you can see in a friendly way where your branches are pointed at. graph: shows a graph…

git log
git log --graph --decorate

How git works internally