Beginner · 8 min · practise every command in the built-in terminal

Staging and Committing

Stage changes

git add file.txt          # Stage one file
git add file1.txt file2.txt
git add .                 # Stage everything in current directory
git add -A                # Stage everything in the whole repo

Staging means "mark this change to be included in the next commit".

Commit staged changes

git commit -m "Add initial project files"

A commit is a permanent snapshot with a message explaining why, not just what.

Stage and commit in one step (tracked files only)

git commit -am "Fix typo in README"

Note: -a only works for files Git already tracks — new files still need git add first.

Undo staging

git restore --staged file.txt     # Unstage, keep changes

Good commit messages

# Bad
git commit -m "stuff"

# Good
git commit -m "Fix login redirect bug for expired sessions"

Practice tasks

  1. Create a file called hello.txt, then stage it with git add
  2. Commit the staged file with a message
  3. Stage every changed file in the current directory at once
  4. Stage and commit changes to tracked files in one step

Commands in this lesson

Git & Version Control