Git

How to Use Git Shell Commands

While starting work on Git, it is necessary to get familiar with the Git-shell commands that can be executed on the command line and easily automated using scripts or other tools. It can be useful for tasks that need to be repeated frequently or for complex workflows that require multiple Git commands to be executed in a specific order.

This guide will illustrate:

What are Git Shell Commands?

Git shell commands are a set of commands that are utilized for interacting with Git. It is a version control system used by developers for tracking changes made to source code and collaborating on software projects. The Git shell is a command-line interface that permits the developers to execute Git commands directly from the terminal or command prompt.

How to Use Git Shell Commands

There are multiple Git shell commands, that are as follows:

    • git init”: Initializes a new local Git repository in the current directory.
    • git add”: track changes to the staging area from the working area.
    • git commit”: Commit/push changes from the staging area to the local repository.
    • git branch”: Lists all available branches or generate a new branch.
    • git checkout”: Switch between branches or check out to a specific commit.
    • git clone”: Generate a copy of a Git repository.
    • git push”: Push committed modifications to a remote repository.
    • git pull”: Pull changes from a remote repository to the local repository.
    • git merge”: Merge changes between branches and repositories.
    • git log”: Display the history of all commits created to the repository.
    • git status”: Show the current status of the working repository.

To use the Git shell commands, first, install the latest version of Git on your system. Then, we will execute some Git shell commands for better understanding.

Initialize a New Repository

Run the below-given command to initialize a new repository:

git init testRepo

 
The resultant image shows that the repository has been initialized successfully:


To start working on the initialized repository, move toward the repository by running the “cd” command:

cd testRepo

 

Check Status

To view the status of the Git local working repository, run the “git status” command:

git status

 
The below-stated output indicates that the working area is cleaned:


Generate Files and Track

Now, create new files by running the “touch” command:

touch f1.txt f2.html

 

Then, execute the “git add .” command for adding all the changes to the staging area:

git add .

 

Commit Changes

Execute the “git commit” command to commit all tracked changes:

git commit

 
As a result, the specified editor has been launched. Add the commit message, save changes by pressing the “CTRL + S” keys, and close the editor:


The provided image shows that the changes have been committed successfully:


That’s all about using the Git shell commands.

Conclusion

Git shell commands are a set of commands that are utilized with Git for interacting. Some most commonly used Git shell commands are “git init”, “git add”, “git branch”, “git clone” and “git commit”. To use Git shell commands, install the Git Bash utility and execute these commands. This tutorial explained the method for using the Git shell commands.

About the author

Hafsa Javed