Tuesday, 18 November 2025

Creating a git repository: git init

What git init does

Run  git init in the folder where your code will be based (this assumes you have already created an appropriately named folder and done cd into it).

This creates a .git subdirectory.

What does the .git subdirectory hold?

.git is filled with configuration files and a subfolder for snapshots to be stored. All commits are stored in .git as well.

Name of initial branch

This may change in successive versions of Git, but as of 2.34, the name of the initial branch created by git init is 'master' (other commonly used names include 'main' and 'trunk' and 'development').

Re-running git init

Re-running git init will not do anything. It will simply output "Reinitializing existing Git repository" in /home/YOURLOGIN/YOURPROJECT/.git/. 

Re-running git init in the .git subdirectory

This is weird and will create a new . git subdirectory in the .git subdirectory, so if you do this, you need to clean up your .git. There is no valid use case for doing this.

Renaming a branch in git

The git branch command can be used to rename the branch.

No comments: