DEV Community

Cover image for Git Command Line Mastery: 10 Essential Commands for Version Control Using Git
Uduakabasi Umo-Odiong
Uduakabasi Umo-Odiong

Posted on

Git Command Line Mastery: 10 Essential Commands for Version Control Using Git

OVERVIEW
Using the command line to carry out version Control on Git. In this article, I will highlight the important commands you need to know, what they are used for and how to use them.

INTRODUCTION
Version control is a game-changer in the tech world, especially when things change and evolve. It’s all about keeping track of the different versions and updates you make to your applications or websites, making monitoring progress and integrating new features easier.
The most popular tool for this task is Git and then there's GitHub, an online platform that brings Git into the cloud, making it even simpler to work together with others.

VERSION CONTROL
Version control can simply be defined as the systematic monitoring and management of versions and changes made to your application, allowing for easy modification, integration, and collaboration among developers. This approach enables teams to keep a detailed history of all modifications, making it possible to track who made specific changes, when they were made, and why.

GIT
Git is a powerful version control system that allows developers to manage and track changes in applications and websites effectively. It supports developers by enabling them to create branches for new features or bug fixes without affecting the main code. It is important to note that GitHub is a web-based platform that utilizes Git.

COMMAND LINE INTERFACE(CLI)
Sometimes referred to as a terminal. This can simply be seen as an essential tool for developers that gives them a text-based way to interact with their operating systems. It enables users to run commands swiftly and carry out other tasks much more efficiently than they could with graphical interfaces.

PREREQUISITE
i) An Ubuntu terminal
ii)Basic knowledge of what Git does and how it works

COMMANDS YOU NEED

GIT CONFIG
The git config command is like your personal settings menu for Git. It lets you customize how Git works for you by adjusting your username and email.

  • To configure your name :
git config --global user.name <Your Name>
Enter fullscreen mode Exit fullscreen mode

Image description

  • To configure your email address:
 git config --global user.email "me@gmail.com"
Enter fullscreen mode Exit fullscreen mode

Image description

  • To view all your current Git configuration settings (including user credentials):
git config --list
Enter fullscreen mode Exit fullscreen mode

Image description

GIT INIT
The git init command creates a new Git repository in a folder, setting it up to track changes to your files. It's the first step to start using Git for version control on a project.

To Create a new repository:

git init <repository-name>
Enter fullscreen mode Exit fullscreen mode

Image description

GIT CLONE
The git clone command makes a copy of an existing Git repository from a remote location to your local machine. You just need the URL of the remote repository which can be gotten from the GitHub website to carry this out.
Clone an existing repository:

git clone <repository-url>
Enter fullscreen mode Exit fullscreen mode

Image description

GIT STATUS
The git status command shows you the current state of your Git repository. It tells you which files have been changed, which are staged for the next commit, and which are untracked.
Check the status of the repository:

git status
Enter fullscreen mode Exit fullscreen mode

Image description

GIT ADD
When you modify files in your repository, those changes are not automatically tracked by Git until you run git add. This command instructs git to monitor changes and any action carried out in that repo.

Add changes to the staging area:

git add <file>
Enter fullscreen mode Exit fullscreen mode

Image description

NB: To add all files

git add . 
Enter fullscreen mode Exit fullscreen mode

GIT COMMIT
The git commit command is how you save your changes in a Git repository. When you run it, Git creates a new commit that captures everything you've added with git add. Each commit comes with a message that explains what changes were made.

Commit changes:

git commit -m "Commit message"
Enter fullscreen mode Exit fullscreen mode

Image description

GIT LOG
The git log command lets you view the history of commits in your Git repository. When you run it, Git displays a list of all the commits, along with their unique identifiers, dates, and messages.
View commit history:

git log
Enter fullscreen mode Exit fullscreen mode

Image description

GIT BRANCH
In Git, a branch is a separate space for development within your project repository. The git branch command is what you use to manage these branches. It lets you create new ones, see a list of all the branches you have, and delete.
Create a new branch:

git branch <branch-name>
Enter fullscreen mode Exit fullscreen mode

Delete a branch:

git branch -d <branch-name>
Enter fullscreen mode Exit fullscreen mode

Image description

GIT DIFF
The git diff command is a tool that helps you see the differences between files or changes in your project.

Show changes in the working directory:

git diff
Enter fullscreen mode Exit fullscreen mode

Image description

GIT PUSH
When you’ve made changes to your project or website and you’re ready to share those changes with your team or just want to back them up, you use git push.

To send changes to the remote repository:

git push origin main
Enter fullscreen mode Exit fullscreen mode

Image description

BONUS COMMAND
GIT HELP
The git help command is like having a handy reference guide right in your terminal. It provides you with information about Git commands, options, and how to use them.
To get all git commands and their options:

git help
Enter fullscreen mode Exit fullscreen mode

Image description

CONCLUSION
In conclusion, version control is a system used to monitor and track changes to your project or website. The usual way to go about this is over the Githug website but from the commands above, I have explained them and how they are used in case there is a need for you to use git on the command line.

This article seeks to highlight the essential commands needed to carry out version control using git. However, there are other secondary commands that are still implemented on git over the command line. As explained above, these can be seen and accessed through the git help command.

On this note, if you ever find yourself using Git on the command line for a Version Control task, do well to follow this article. If you come across any challenges or have any feedback to give, I would appreciate it if you reached out to me through my LinkedIn.
Thank You.

Top comments (4)

Collapse
 
horpeyemi profile image
Opeyemi Alabi

Great write-up.
This is well concise.

Collapse
 
dheecloud profile image
Uduakabasi Umo-Odiong

Thank you so much

Collapse
 
ovrobin profile image
Victor Robin

Nice share, you know your onion in this thing. 👏👏

Collapse
 
dheecloud profile image
Uduakabasi Umo-Odiong

thank you my oga