Git Get Started

With Git installed and configured, you are ready to turn any folder into a repository and record your first commit.

Creating a New Repository

Turning a plain folder into a Git repository is done with a single command: git init. This creates a hidden .git subfolder that holds the entire history, configuration, and internal database for the project. Nothing outside that hidden folder is touched, so git init is always safe to run.

Example

$ mkdir my-project
$ cd my-project
$ git init
Initialized empty Git repository in /home/user/my-project/.git/

Checking Repository Status

The git status command is the one you will run more than any other. It tells you which branch you are on, which files have changed, which changes are staged for the next commit, and which files Git does not yet know about.

Example

$ echo "# My Project" > README.md
$ git status
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	README.md

nothing added to commit but untracked files present (use "git add" to track)
  • Untracked: a new file Git has never seen before
  • Modified: a tracked file that has changed since the last commit
  • Staged: a change marked to be included in the next commit
  • Committed: a change permanently saved in the project history
Note: 'On branch main' confirms the default branch name. Older Git installations, and some tutorials, may still show 'master' instead; the two names behave identically.

Making Your First Commit

Committing is a two-step process in Git: first you stage the changes you want to include with git add, then you save them permanently with git commit. This separation is intentional and is covered in depth in the next chapter on staging.

Example

$ git add README.md
$ git commit -m "Add project README"
[main (root-commit) 3f2a1c9] Add project README
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
CommandPurpose
git initCreate a new, empty repository in the current folder
git statusShow the current state of tracked and untracked files
git addStage changes so they will be included in the next commit
git commitPermanently save the currently staged changes
Note: git init only needs to be run once per project. Running it again inside an existing repository is harmless but pointless, and running 'git init' inside the wrong folder can create a stray, empty repository you did not intend.

Exercise: Git Get Started

What does `git init` do?