Git & GitHub·Set up and understand Git

Installing and configuring Git

Check your installation, tell Git who you are and pick sensible defaults before your first commit.

Beginner 10 min read Lesson 3 of 480 Challenge included
What you will be able to do
  • Check that Git is installed and read its version
  • Set your commit name and email once with git config
  • Choose main as the default branch and configure line endings
  • Create a new repository with git init

In plain English

Git is a version control tool: it saves a history of every change you record to a project, which is a folder of files called a repository. A commit is one saved snapshot of your files, and Git labels it with your name and email, so you must configure those first. The default branch is the main line of your history, and main is the modern standard name for it. Line endings are the invisible characters at the end of each text line, which differ between operating systems, so Git can convert them automatically for you.

Step by step

  1. 1Check your installation by asking Git for its version.
  2. 2Set your name and email, which Git stamps on every commit you make.
  3. 3Choose main as the default branch name for new repositories.
  4. 4Configure line-ending handling so text files stay consistent across machines.
  5. 5Create a project folder and turn it into a repository with git init.
one-time setupTerminal
git --version
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"
git config --global init.defaultBranch main
git config --global core.autocrlf input
git config --list
mkdir my-project
cd my-project
git init

Common mistakes

  • Forgetting to set user.name and user.email, so commits are recorded with no clear author.
  • Running git init inside a parent folder that already contains other repositories, which nests projects together.
  • Skipping the version check and then being confused when a command does not exist.
  • Panicking over line-ending settings, which can be changed at any time without losing work.
Your turn

Configure Git from scratch

Easy

Set your name to 'Ada Lovelace', your email to 'ada@example.com', make main the default branch, then create a repository in a folder called my-project.

BASH · starter
Check your understanding before moving on.
Knowledge checkQuestion 1

Which command confirms Git is installed and shows its version?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Reading diffs and logs
Lesson 3 of 480 · 0% of course