Skip to content
Snippets Groups Projects
README.md 6.89 KiB

Git Command Line Basics

All Git commands start with the git "main" command followed by a keyword matching the Git operation to be performed. Running Git commands only works inside folders that belong to a (local) Git repository. Trying to run Git commands outside a Git repository folder will generate an error message.

This index lists all the available commands with links to extensive documentation.

Displaying information about a local repository

The git status command displays information about the current status of the local repository:

  • What is the current branch ?
  • If it is related to a remote branch, have any modifications been made on either side ?
  • What has happend to the files and folders of the local repository ?

Important note

  1. By default Git ignores files with a predefined list of suffixes, considering they are generated by some complation process, and should not be included in a Git repository. These files will not show up in the output of git status.

On a freshly cloned repository, the output of git status looks like:

status_initial.png

The git log command details all the operations that have been performed on the current branch since it was created, crouped by commits. git log provides many many options to customize the output.

On the freshly cloned example repository, the output of git log looks like:

log_initial.png

Making changes to a local repository

You can make any changes to a local repository (adding, removing, renaming files and folders, editing files). Git will take note of what has changed and you can always use git status to view the changes.

For example, after editing the contents of the README.md file, git status will display:

status_after_changes.png

Notice that Git mentions that the README.md and the imaginary.md files have been modified but has not been staged for commit. The same is true for the newly added images/bigfoot.jpeg file. This means that even if you try git commit right now, nothing will be commited.

Notifying Git which changes have to be included in the next commit.

Git has to be explicitely made aware of what changes you want to include in the next commit.