Dualo
Git & GitHub

Initialize a repository

`git init` turns any folder into a Git repository. A hidden `.git/` directory appears — that's where the entire history lives.

1 min read

git init creates a .git/ directory containing the repository database. Default contents: objects/ (the content store), refs/heads/ (branch pointers, empty initially), HEAD (symbolic ref pointing to refs/heads/main or master depending on init.defaultBranch), config (per-repo config), description, info/, hooks/.

Default branch name: since Git 2.28 you can set init.defaultBranch (git config --global init.defaultBranch main). GitHub defaults to main; legacy repos still use master. Both are just branch names — Git itself is agnostic.

Bare vs non-bare: git init --bare creates a repo with no working tree, used for server-side hosting (GitHub stores bare repos internally). The convention is to name bare repos *.git (e.g., dualo.git).

git clone <url>: equivalent to git init + git remote add origin <url> + git fetch origin + git checkout <default-branch>. The URL can be HTTPS (https://github.com/user/repo.git), SSH (git@github.com:user/repo.git), or local (/path/to/repo).

Identity config: per-repo config (.git/config) overrides global (~/.gitconfig) which overrides system (/etc/gitconfig). Unsigned commits use user.name/user.email verbatim. Signed commits (git commit -S) require a GPG/SSH key configured via user.signingkey.

Re-initializing: running git init in an existing repo is safe — it re-creates missing files but doesn't touch existing history. Useful to upgrade an old repo's .git/ layout or fix a corrupted HEAD.

Practice

Type the command to turn the current folder into a new Git repository.

Practice

Type the command to download an existing repo from `https://github.com/user/repo.git`.

Practice

Set your global Git identity:

git config user.name "Ton Nom" / git config --global user.email

Grounded on https://git-scm.com/docs/git-init

Next up

The three trees: working, staging, repository

Git has three areas: the files you edit (working tree), the changes you've prepared (staging), and the committed history (repository). Every Git command moves data between these.