Tech Hub

@ Solution Architecture Works

GitHub Fundamentals – Part 1 of 2

Basic Git Commands

Estimated reading: 3 minutes 11 views

Git works by recording changes made to your files, like taking snapshots of your file system.

We’ll cover a few basic commands to start tracking files in your repository. Then, you’ll save your first “snapshot” that Git can use as a comparison point.

git status

The first Git command, and the most commonly used, is git status.
You’ve already used it in the previous exercise to check that you had successfully initialized your Git repository.

git status displays the state of the working tree (and the staging area — we’ll talk about that soon).
It lets you see which changes are currently being tracked by Git, so you can decide whether to ask Git to take a new snapshot.

git add

git add is the command you use to tell Git to start tracking changes in specific files.

The technical term is to stage these changes.
You’ll use git add to prepare changes for a commit.
All changes in files that have been added but not yet committed are stored in the staging area.

git commit

Once you’ve staged changes for a commit, you can save your work as a snapshot using the git commit command.

The word commit is both a verb and a noun.
It essentially means the same as when you commit to a plan or confirm a change in a database.

  • As a verb, to commit changes means to save a copy (of the file, directory, etc.) in the repository as a new version.
  • As a noun, a commit is a small block of data that gives a unique identity to the changes you’ve saved.

The data recorded in a commit includes:

  • the author’s name and email address,
  • the date,
  • comments about what you did (and why),
  • an optional digital signature,
  • and the unique ID of the previous commit.

git log

The git log command lets you view information about previous commits.
Each commit has an associated message (commit message), and git log displays information about the most recent commits, such as:

  • their timestamp,
  • the author,
  • and the commit message.

This command helps you track what you’ve done and what changes have been recorded.

git help

You’ve already tried the git help command, but it’s worth mentioning again.
Use this command to easily get information about all the commands you’ve learned so far — and many more.

Remember that each command also has its own help page.
You can access these pages by typing:

git --help

For example:
git commit --help displays a page that tells you more about the git commit command and how to use it.

Share this Doc

Basic Git Commands

Or copy link

CONTENTS