Skip to content

DevOps Operations / Git · Step 1 of 8

Lesson: Git RepositoriesSwitch
← DevOps Operations

Delivery and containers

Git Repositories

Learn what a Git repository is, how to create or clone one, and where Git keeps its data.

A repository (or "repo") is a project folder whose history Git records. You can go back to earlier versions, see who changed what, and share the work with others.

Create a repository

Run git init inside a project folder:

$ mkdir notes
$ cd notes
$ git init
Initialized empty Git repository in /home/sam/notes/.git/

Your existing files are not recorded yet. Git only starts keeping history once you add files and commit them. Depending on your Git version and settings, the first branch is called master or main, and Git may print a hint about it.

The .git directory

git init creates a hidden directory named .git:

$ ls -a
.  ..  .git

This directory holds the history, the branches and the settings for this repository. The files you see and edit around it are called the working tree. If you delete .git, the files in the working tree stay, but the local history is gone. Do not edit its contents by hand while you are learning.

Clone an existing repository

To get a copy of a project that already exists, use git clone with its address:

$ git clone https://example.com/team/website.git
Cloning into 'website'...

The address above is a placeholder, so replace it with a real one. Cloning creates a new folder, downloads the history, checks out a branch, and remembers the source under the name origin. You do not run git init first.

You can pick a different folder name by adding it at the end:

$ git clone https://example.com/team/website.git site

Tell Git who you are

Every commit records an author. Set your name and email once per user account:

$ git config --global user.name "Sam Lee"
$ git config --global user.email "[email protected]"

Leave out --global inside a repository to set a value for that repository only.

The official git init documentation lists every option. If you are not yet comfortable moving between folders, practise in the shell navigation lab.

Try it

Create a folder called practice, run git init inside it, and list the contents with ls -a. Then run git status and read what Git says about the empty repository.

Check your understanding

Git Repositories

All 3 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.