Git & Command Line Tutorial · Git Basics · Lesson 8 of 20

Setting Up Git and Creating a Repository

Configure your name and email, set the default branch to main, create a repository with git init, and understand what the .git folder is.

Create a free account to save this page, take notes and track your progress. Sign in

One-time setup

Tell Git who you are; this goes into every commit:

git config --global user.name "Ana Dev"
git config --global user.email "[email protected]"
git config --global init.defaultBranch main
git config --global pull.rebase false     # or true, see the Rebasing page

git config --list shows your settings; --global settings live in ~/.gitconfig.

A new repository

git init turns the current folder into a repository by creating a hidden .git folder, which stores the entire history. Delete .git and the history is gone, but your files stay.

To copy an existing repository instead, use git clone <url> (see Remotes).

git config and git init
git config --global user.name "Ana Dev"
git config --global user.email "[email protected]"
git config --global init.defaultBranch main
git config --global --list

mkdir recipes && cd recipes
git init --quiet
echo "--- branch: $(git branch --show-current)"
ls -A
ls .git | head -6
git status

Output

user.name=Ana Dev
[email protected]
init.defaultbranch=main
--- branch: main
.git
HEAD
branches
config
description
hooks
info
On branch main

No commits yet

nothing to commit (create/copy files and use "git add" to track)

Run this on your computer — see “Get Started” for setup.

Test yourself

Where does Git store a repository's history?

  1. In ~/.gitconfig
  2. In the hidden .git folder
  3. On GitHub only
  4. In README.md
Show answer

Answer: In the hidden .git folder

Was this page helpful?