liveBook · Manning

Git init command

As explained in Road to Kubernetes

git init is a Git command that creates or reinitializes a repository in a directory.

git init creates a Git repository in the directory where you run it, allowing Git to manage that project's changes. The repository is initially local, and Git does not track files until you add and commit them. section 2.3.1 section 2.3.6

Initialize two web-app projects

Run the command from each project directory: cd ~/Dev/roadtok8s/py/ followed by git init, then cd ~/Dev/roadtok8s/js/ followed by git init. Git reports that it initialized an empty repository. Check whether a directory is already a repository with git status; running git init there reinitializes the existing repository instead. section 2.3.1

A typical setup continues after initialization:

  • Create a .gitignore file for files Git should ignore. section 2.3.4
  • Run git add to select files, then git commit -m "Commit message" to record them. section 2.3.4
  • Add a remote and push when the repository should be hosted elsewhere. section 2.4.3
Listing 2.23 Using git init to initialize a Git repository
cd ~/Dev/roadtok8s/py/
git init

Shows the minimal command sequence for initializing the Python project; the equivalent Node.js listing is also available. section 2.3.1

For a server-side remote repository, git init --bare creates a repository without a working directory; the setup also assigns HEAD to the main branch. section 3.3.2

How Road to Kubernetes covers it

How deep it goes
Explains directory scope, reinitialization, status checking, and the follow-on add-commit workflow, while deferring branching details.
Examples
Uses Python and Node.js project directories plus VM-hosted bare repositories as initialization examples.
What it assumes
Assumes a project directory and basic command-line navigation, while teaching repository initialization and the first tracking steps.
What you can do after
Operate Git to initialize, check, reinitialize, and prepare repositories for tracking and remote pushes.
How it connects
Connects Git repositories with git status, git add, git commit, git push, GitHub, bare repositories, and branches.

Also explained in

Compare how 2 books explain git init command →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.