What Is Git? Start a Repository With git init
Version control records the history of a set of files so you can see what changed, when and why, and go back to any earlier state. Instead of folders called final, final2 and final-really, you have one folder and a complete, searchable history.
Git is the version control system used by almost every software team today. It is distributed: every copy of a project contains its full history, so you can commit, browse history and create branches offline. Sites like GitHub and GitLab host shared copies, but Git itself is a program on your computer.
Repositories
A Git repository (repo) is a project folder that Git tracks. git init turns the current folder into one by creating a hidden .git directory. Everything Git knows (every saved version, every branch, your settings for this repo) lives inside .git. Delete it and the folder becomes an ordinary folder again, with your current files untouched but the history gone.
One-time setup
Before your first commit, tell Git who you are. These values are written into every commit you make:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Recent Git versions also let you choose the name of the first branch with git config --global init.defaultBranch main.
git status: your dashboard
git status tells you which branch you are on and how each file stands. Run it constantly; it is read-only and often suggests the next command. A brand new file shows up as untracked: Git sees it but is not recording it yet.
mkdir recipes
cd recipes
git init -q
ls -a
git status
echo "Pancakes: flour, milk, eggs" > pancakes.txt
git status Transcript (verified by our test suite in a fresh temp folder)
$ mkdir recipes $ cd recipes $ git init -q $ ls -a . .. .git $ git status On branch main No commits yet nothing to commit (create/copy files and use "git add" to track) $ echo "Pancakes: flour, milk, eggs" > pancakes.txt $ git status On branch main No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) pancakes.txt nothing added to commit but untracked files present (use "git add" to track)
The transcript creates a folder, runs git init, shows the hidden .git directory with ls -a, then creates a file and checks git status. Notice the hint Git prints about how to start tracking the file. The next chapter does exactly that.
Is Git the same as GitHub?
No. Git is the tool; GitHub is a website that hosts Git repositories and adds features like pull requests and issues. You can use Git for years without any hosting service, and you can move a repository between hosts because the full history travels with it.
Common mistakes
- Running
git initin your home directory by accident, which makes everything below it look like one giant project. If that happens, remove the stray.gitfolder there. - Skipping the name and email setup, which makes the first commit fail or record a guessed identity.
Summary
- Version control keeps a full history; Git is the standard, distributed tool.
git initcreates a repository by adding a.gitdirectory.git statusshows the branch and the state of each file.
Quiz: What Git is