Major Git Commands

Learn how to use the major Git commands for version control.

Introduction

Git offers different commands for working with a Git repository. Some of the use cases for these commands include the following:

  • Creating a new branch
  • Adding and committing new changes
  • Editing changes locally
  • Fixing mistakes
  • Working with a remote repository

There are quite a few Git commands—we’ll look at some of them below.

Note: To start working with these commands, please note that there are important steps that need to be performed. Please refer to the previous lesson to do the following:

  1. Configure credentials
  2. Initialize a new repository

Major Git commands

The git add command

The git add command adds the files in the developer’s working directory to the staging area, which is a snapshot of related changes. The git add command shows the files that will be included as part of the next commit.

A file is added to the staging area by typing the following command in the terminal:

git add <filename>

All files present in the current working directory are added to the staging area by typing the following command in the terminal:

git add .

The git stash command

The git stash command is a means of saving changes temporarily. In a situation where we are working on a feature and aren’t ready to add it as part of the next commit, we can make use of git stash to temporarily save the change. The git stash command stores changes inside a .git directory (/.git/refs/stash).

Changes can be stashed by typing the following command in the terminal:

 ...