Installing and configuring Git
Check your installation, tell Git who you are and pick sensible defaults before your first commit.
- 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
- 1Check your installation by asking Git for its version.
- 2Set your name and email, which Git stamps on every commit you make.
- 3Choose main as the default branch name for new repositories.
- 4Configure line-ending handling so text files stay consistent across machines.
- 5Create a project folder and turn it into a repository with git init.
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 initCommon 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.
Configure Git from scratch
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.
Which command confirms Git is installed and shows its version?
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Lock in what you just learned.
Mark this lesson complete to save your place and move one step closer to the certificate.