DEV Community

Cover image for Using the GIT CLI
Aadityasiva
Aadityasiva

Posted on

Using the GIT CLI

In this post I will be explaining how to use the GIT CLI(Command Line Interface). This will require GIT to be installed on your device if you don't have it then install it by following the steps mentioned in the previous post.

Before we start

If you want to check if GIT is installed run this command

git --version
Enter fullscreen mode Exit fullscreen mode

And if it prints out the version number you are good to go.

Making a GIT repository with the CLI

To make a GIT repository with the CLI run this

git init
Enter fullscreen mode Exit fullscreen mode

This will initialize an empty repository

Moving files to the staging area with GIT

To add a single file to the staging area run this

git add <FILE TO ADD>
Enter fullscreen mode Exit fullscreen mode

To add all the changed files to the staging area run this

git add .
Enter fullscreen mode Exit fullscreen mode

Committing changed files

To commit the files in the staging area to the main repository we need to run.

git commit -m "<insert commit message here>"
Enter fullscreen mode Exit fullscreen mode

Viewing all commits in a repository

git log
Enter fullscreen mode Exit fullscreen mode

This command will log all the commits made to a repository

Reverting a commit

In order to revert a commit you will need to know the commit id it can be known by running git log

git revert <commit id>
Enter fullscreen mode Exit fullscreen mode

Making a new branch

A branch is a copy of the main files it lets you test out features or something else which does not conflict with the main branch so to make a new branch you need to run

git checkout -b your-branch-name
Enter fullscreen mode Exit fullscreen mode

Viewing the list of branches

To see the list of branches run this

git branch -a
Enter fullscreen mode Exit fullscreen mode

Switching branches

This command will switch the branch

git checkout -b your-branch-name
Enter fullscreen mode Exit fullscreen mode

Merging branches with the main branch

To merge a branch with the main branch run this

git merge your-branch-name
Enter fullscreen mode Exit fullscreen mode

There are many more commands there but for now I am ending the post here bye and have a nice day!

Top comments (1)

Collapse
 
programmeraadi profile image
hmmmmmmcoder

Nice