読み物Git

Level: Basic

Getting Started with Git: Installation, Setup, and Your First Repository

Install Git on Windows, macOS, or Linux, configure your identity and default branch, create your first repository, and look inside the .git folder.

Edeeson Opina7 min read

A Basic lesson card: lesson 2 of the Git & Version Control series, Getting Started with Git: Installation, Setup, and Your First Repository, with the Miso fox looking curious.

What you’ll learn

  • Install or update Git on Windows, macOS, or Linux
  • Configure user.name, user.email, and init.defaultBranch
  • Explain system, global, and local configuration levels
  • Create a repository and make a first commit
On this page
  1. Before you start
  2. Installing Git
  3. Windows
  4. macOS
  5. Linux
  6. Configuring Git
  7. Your identity
  8. The default branch name
  9. A few helpful settings
  10. Creating your first repository
  11. Starting from an existing project
  12. Inside the .git folder
  13. Authentication comes later
  14. Common mistakes and troubleshooting
  15. Practical exercise: set up and inspect
  16. Key takeaways
  17. References
  18. What's next

The best way to understand Git is to use it. In this lesson you'll install Git on Windows, macOS, or Linux, tell it who you are, choose a few sensible settings, and create your first repository. You'll also look inside the repository folder so that .git stops being a mystery. Everything here happens on your own computer; no account on any hosting platform is needed.

Before you start

Read What Is Version Control? Understanding Git and Repository Hosting for the concepts. You'll need permission to install software on your computer and a terminal: Terminal on macOS, a terminal emulator on Linux, or Git Bash, PowerShell, or Windows Terminal on Windows.

Installing Git

First check whether Git is already installed:

Shell
git --version

If you see something like git version 2.51.0, you're ready; skip to the configuration section. The latest release on the Git website was 2.56.0 in September 2026. Any reasonably recent 2.x version works for this series, but updating is worthwhile because releases include security fixes.

Windows

Download Git for Windows from the official Git website, or install it with the Windows Package Manager:

Shell
winget install --id Git.Git -e --source winget

The installer asks several questions. The defaults are fine for most people. Two choices are worth understanding:

  • Line endings: "Checkout Windows-style, commit Unix-style" (core.autocrlf=true) is the usual choice on Windows, so files in the repository use LF while your editor sees CRLF.
  • Credential helper: keep Git Credential Manager, which stores your hosting platform credentials securely in Windows.

Git for Windows includes Git Bash, a terminal with common Unix commands, which matches the examples in this series.

macOS

macOS offers to install the Xcode Command Line Tools, which include Git, the first time you run git. For a more current version, use Homebrew:

Shell
brew install git

Linux

Use your distribution's package manager:

Shell
# Debian, Ubuntu
sudo apt update && sudo apt install git

# Fedora
sudo dnf install git

# Arch Linux
sudo pacman -S git

Distribution packages can lag behind the latest release. If you need newer features, your distribution may offer a backports repository, or you can build from source.

Configuring Git

Git stores settings at three levels:

  • System (--system): every user on the machine.
  • Global (--global): your user account, in ~/.gitconfig.
  • Local (--local, the default inside a repository): one repository, in .git/config.

More specific levels override less specific ones, so a repository can use a different email from your global one.

Your identity

Every commit records an author name and email. Set them once:

Shell
git config --global user.name "Ada Example"
git config --global user.email "ada@example.test"

This isn't an account or a login. It's text written into each commit. Hosting platforms use the email to link commits to your profile, so use an address registered with your account there. If you don't want to publish a personal address, most platforms provide a private "no-reply" address you can use instead.

The default branch name

When you create a repository, Git creates a first branch. Current versions still call it master unless you choose otherwise, and print a hint about it:

Shell
$ git init recipes
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: 	git config --global init.defaultBranch <name>

Most hosting platforms now create main as the first branch, and Git's own plans for version 3.0 change the default to main too. Set it once to avoid mismatches:

Shell
git config --global init.defaultBranch main

A few helpful settings

Shell
# Your editor for commit messages (examples: VS Code, nano, vim)
git config --global core.editor "code --wait"

# Make `git pull` refuse to create surprise merge commits (lesson 5 explains)
git config --global pull.ff only

# Colors in the terminal (usually on by default)
git config --global color.ui auto

Check what's set, and where each value comes from:

Shell
git config --list --show-origin

Creating your first repository

Create a project folder and turn it into a repository:

Shell
mkdir recipes
cd recipes
git init

Git replies Initialized empty Git repository in …/recipes/.git/. Check the state:

Shell
$ git status
On branch main

No commits yet

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

Add a file and make your first commit:

Shell
echo "# Recipes" > README.md
git add README.md
git commit -m "Add README"
git log --oneline

The last command shows one line: a short commit ID and your message. You've recorded the first snapshot of your project. Lesson 3 explains each of these commands properly.

Starting from an existing project

If a folder already has files, run git init inside it, then add and commit the files you want tracked. Before your first commit, create a .gitignore so you don't accidentally commit dependencies, build output, or secrets (lesson 3).

Inside the .git folder

The .git folder is Git's database. You'll rarely touch it directly, but knowing what's there removes the mystery:

Shell
$ ls .git
HEAD  config  description  hooks  index  info  objects  refs
  • HEAD: which branch you're on.
  • config: settings for this repository.
  • objects/: the stored content: file versions, directory listings, and commits.
  • refs/: branch and tag names, each pointing at a commit.
  • index: the staging area.
  • hooks/: optional scripts Git can run at certain moments, such as before a commit.

Don't edit these files by hand; use Git commands. And never delete .git unless you mean to throw away the history.

Authentication comes later

You don't need any credentials to use Git locally. You need them only to push to, or fetch private repositories from, a hosting platform. Lesson 5 covers SSH keys and HTTPS tokens. One rule now: platforms no longer accept your account password for Git over HTTPS; you'll use a token, a credential manager, or SSH keys.

Common mistakes and troubleshooting

  • "git: command not found." Git isn't installed, or your terminal was open before installation. Open a new terminal; on Windows, check that Git was added to PATH during installation.
  • "Please tell me who you are." You haven't set user.name and user.email. Set them as shown above.
  • Commits under the wrong email. Check git config user.email inside the repository; a local setting may override your global one.
  • Running git init in your home folder. That turns your whole home directory into a repository. Remove the accidental .git folder there (rm -rf ~/.git, after checking it's the wrong one) and run git init inside a project folder instead.
  • Branch named master locally and main on the platform. Rename with git branch -m main, and set init.defaultBranch for next time.
  • Line ending warnings on Windows ("LF will be replaced by CRLF"). These are informational. A .gitattributes file with * text=auto makes behavior consistent for the whole team.

Practical exercise: set up and inspect

  1. Install or update Git, and run git --version.
  2. Set your name, email, default branch, and editor globally; confirm with git config --list --show-origin.
  3. Create a folder called notes, run git init, and run git status.
  4. Create README.md with one line, add it, commit it, and run git log.
  5. Run cat .git/HEAD and ls .git/refs/heads. What do they tell you about your current branch?
  6. In this repository only, set a different user.email with git config user.email, make a second commit, and compare the two commits' authors with git log --format='%h %an <%ae>'.

Key takeaways

  • Install Git from your platform's package manager or the official installer, and keep it updated.
  • Configure user.name, user.email, and init.defaultBranch once, globally.
  • Settings live at system, global, and local levels; local wins.
  • git init creates a repository; .git is its database.
  • No hosting account is needed to use Git.

References

What's next

With Git installed and a repository created, Git Fundamentals: Commits, Staging, History, and .gitignore covers the commands you'll use every day.

See every lesson in Git & Version Control: From Fundamentals to Advanced Workflows