← All topics

GIT & VERSION CONTROL · REFERENCE

Repositories and Files

Choose between starting history in an existing folder and copying a repository that already exists.

At a glance

Term or command What it means When to use it
git init -b main Creates Git metadata and starts a branch named main. Use once when beginning tracking in your own project folder.
git clone URL Creates a new local copy of an existing repository. Use when the project already has a repository elsewhere.
.git/ Git’s internal metadata and history in an ordinary repository. Let Git manage it. It is normally hidden in file managers.
Tracked / untracked Tracked files are known to Git; untracked files are not yet in its index or history. Read status to decide what to add.
.gitignore Patterns for intentionally untracked files. Exclude generated output, local settings, and secrets before adding them.
git check-ignore -v Explains the ignore rule matching a path. Use when a new file does not appear as expected.

Commands are examples, not an interactive terminal. Run them in your own learning repository after checking the prerequisites. Output, paths, commit IDs, and wording can vary. Host-specific instructions are labeled.

Two starting routes

For your own existing folder, open a terminal there and use init. For a project that already has a remote repository, clone it into a new folder instead. Cloning normally sets up origin for you; init does not create a remote.

git init -b main

Alternative: replace the URL with one copied from a real repository you can access. The domain below is a placeholder, not a real host to sign into.

git clone https://git.example.org/your-name/my-website.git
cd my-website

What the project looks like

my-website/
├── .git/          Git-managed history and metadata
├── .gitignore     Rules for untracked files
├── index.html     Your website content
└── css/
    └── styles.css

The .git folder belongs to this repository. Do not edit it by hand. Downloading a ZIP of source files is different from cloning: the ZIP generally does not include the Git history and remote configuration. Git does not track empty directories by themselves.

Ignore local and generated files

Create .gitignore in the project root before staging. These are example rules; adjust them for the project.

.env
.env.*
!.env.example
node_modules/
dist/
.DS_Store

A trailing slash matches a directory. An asterisk is a wildcard; the exclamation mark makes an exception for a non-secret example configuration file. These names are patterns inside .gitignore, not terminal commands.

Ignoring a file does not remove it from existing history or stop tracking a file already added. If a secret was committed, revoke or rotate it and follow your host’s removal guidance.

Check what will be included

Run inside the initialized project with a saved index.html and .gitignore. Short status uses ?? for untracked paths.

Commands

git status --short
git check-ignore -v .env

Example output

?? .gitignore
?? index.html
.gitignore:1:.env	.env

Check-ignore reports the rule matching .env. A generated file should only be ignored if your project does not need it committed.

Sources and further reading

Study questions

Explain it in your own words, then open the answer.

Should I use init or clone?

Init starts history for your own folder; clone copies a repository that already exists.

Does init create a GitHub repository?

No. It creates local Git metadata.

Does .gitignore erase a committed secret?

No. It is not a history cleanup or credential-revocation tool.

Does downloading a ZIP give me a normal Git clone?

No. It generally contains files without Git history and remote settings.

Why does Git not show my empty folder?

Git tracks files, not empty directories by themselves.