How to use Git via the command line

Last updated on May 27 2022
Suyash Borole

Table of Contents

How to use Git via the command line

Git command line

There are many different ways to use Git. Git supports many command-line tools and graphical user interfaces. The Git command line is the only place where you can run all the Git commands.
The following set of commands will help you understand how to use Git via the command line.

Basic Git Commands

Here is a list of most essential Git commands that are used daily.
• Git Config command
• Git init command
• Git clone command
• Git add command
• Git commit command
• Git status command
• Git push Command
• Git pull command
• Git Branch Command
• Git Merge Command
• Git log command
• Git remote command
Let’s understand each command in detail.
Git config command
This command configures the user. The Git config command is the first and necessary command used on the Git command line. This command sets the author name and email address to be used with your commits. Git config is also used in other scenarios.
Syntax
1. $ git config –global user.name “ImDwivedi1”
2. $ git config –global user.email “Himanshudubey481@gmail.com”
Git Init command
This command is used to create a local repository.
Syntax
1. $ git init Demo
The init command will initialize an empty repository. See the below screenshot.

devops 75
devops

Git clone command
This command is used to make a copy of a repository from an existing URL. If I want a local copy of my repository from GitHub, this command allows creating a local copy of that repository on your local directory from the repository URL.
Syntax
1. $ git clone URL

devops 76
devops

Git add command
This command is used to add one or more files to staging (Index) area.
Syntax
To add one file
1. $ git add Filename
To add more than one file
1. $ git add*

devops 77
devops

Git commit command
Commit command is used in two scenarios. They are as follows.
Git commit -m
This command changes the head. It records or snapshots the file permanently in the version history with a message.
Syntax
1. $ git commit -m ” Commit Message”
Git commit -a
This command commits any files added in the repository with git add and also commits any files you’ve changed since then.
Syntax
1. $ git commit -a

devops 78
devops

Git status command
The status command is used to display the state of the working directory and the staging area. It allows you to see which changes have been staged, which haven’t, and which files aren?t being tracked by Git. It does not show you any information about the committed project history. For this, you need to use the git log. It also lists the files that you’ve changed and those you still need to add or commit.
Syntax
1. $ git status

devops 79
devops

Git push Command
It is used to upload local repository content to a remote repository. Pushing is an act of transfer commits from your local repository to a remote repo. It’s the complement to git fetch, but whereas fetching imports commits to local branches on comparatively pushing exports commits to remote branches. Remote branches are configured by using the git remote command. Pushing is capable of overwriting changes, and caution should be taken when pushing.
Git push command can be used as follows.
Git push origin master
This command sends the changes made on the master branch, to your remote repository.
Syntax
1. $ git push [variable name] master

devops 80
devops
devops 81
devops
devops 82
devops
devops 83
devops

Git push -all
This command pushes all the branches to the server repository.
Syntax
1. $ git push –all

devops 84
devops

Git pull command
Pull command is used to receive data from GitHub. It fetches and merges changes on the remote server to your working directory.
Syntax
1. $ git pull URL

devops 85
devops

Git Branch Command
This command lists all the branches available in the repository.
Syntax
1. $ git branch

devops 86
devops

Git Merge Command
This command is used to merge the specified branch?s history into the current branch.
Syntax
1. $ git merge BranchName

devops 87
devops

Git log Command
This command is used to check the commit history.
Syntax
1. $ git log

devops 88
devops

By default, if no argument passed, Git log shows the most recent commits first. We can limit the number of log entries displayed by passing a number as an option, such as -3 to show only the last three entries.
1. $ git log -3
Git remote Command
Git Remote command is used to connect your local repository to the remote server. This command allows you to create, view, and delete connections to other repositories. These connections are more like bookmarks rather than direct links into other repositories. This command doesn’t provide real-time access to repositories.

devops 89
devops

So, this brings us to the end of blog. This Tecklearn ‘How to use Git via the command line’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Git and GitHub and build a career in DevOps domain, then check out our interactive, Version control with Git and GitHub Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

Version Control with Git and GitHub

Version Control with Git and GitHub Training

About the Course

Tecklearn has specially designed this Git and GitHub Training Course to advance your skills for a successful career in this domain. The course will cover different components of Git and GitHub and how they are used in software development operations. The course consists of important concepts like: branching & merging, how to deal with conflicts, rebasing, merge strategies, Git workflows and so on. You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Git.

Why Should you take Git and GitHub Training?

• Average salary of Git and GitHub Professional is $85k – Indeed.com
• Amazon, Google, Facebook, Microsoft, Twitter, & many other MNC’s worldwide use Git across industries.
• According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.

What you will Learn in this Course?

Introduction to DevOps
• What is Software Development
• Software Development Life Cycle
• Why DevOps?
• What is DevOps?
• DevOps Lifecycle
• DevOps Tools
• Benefits of DevOps
• How DevOps is related to Agile Delivery
• DevOps Implementation
Git and GitHub
• What is version control
• Version Control System (VCS) Products
• Types of VCS
• What is Git
• Why Git for your organization
• Install Git
• Common commands in Git
• Working with Remote Repositories
• GitHub
• Git Installation
• Git Lifecycle
• GitHub (Push, Pull Request)
• GitHub Workflow

 

0 responses on "How to use Git via the command line"

Leave a Message

Your email address will not be published. Required fields are marked *