Important GIT Commands

Important GIT Commands

  • git init: This command is used to initialize a new Git repository in the current directory. For example, you can use the following command to initialize a new Git repository in the myproject directory: $ git init my-project
  • git clone: This command is used to clone an existing Git repository from a remote source. For example, you can use the following command to clone the my-project repository from the https://github.com/user/my-project.git URL:

$ git clone https://github.com/user/my-project.git

  • git add: This command is used to add files to the staging area in a Git repository. For example, you can use the following command to add the file1.txt and file2.txt files to the staging area:

$ git add file1.txt file2.txt

  • git commit: This command is used to commit the changes in the staging area to the Git repository. For example, you can use the following command to commit the changes in the staging area with the commit message "Added new files":

$ git commit -m "Added new files"

  • git push: This command is used to push the committed changes in the local repository to the remote repository. For example, you can use the following command to push the committed changes to the origin remote branch:

$ git push origin

  • git pull: This command is used to pull the changes from the remote repository to the local repository. For example, you can use the following command to pull the changes from the origin remote branch:

$ git pull origin

  • git branch: This command is used to list, create, or delete branches in a Git repository. For example, you can use the following command to create a new branch called my-branch:

 $ git branch my-branch

  • git checkout: This command is used to switch between branches in a Git repository. For example, you can use the following command to switch to the my-branch branch:

 $ git checkout my-branch

  • git log: This command is used to display the commit history of a Git repository. For example, you can use the following command to view the commit history with the author and date information:

 $ git log --pretty=format:"%h %an %ad"

  • git diff: This command is used to view the differences between two versions of a file in a Git repository. For example, you can use the following command to view the differences between the file1.txt file in the HEAD and the my-branch branch:

$ git diff HEAD my-branch file1.txt

  • git stash: This command is used to save the local changes in a Git repository without committing them. For example, you can use the following command to stash the local changes:

 $ git stash

  • git tag: This command is used to add tags to specific commits in a Git repository. For example, you can use the following command to add a tag called v1.0 to the latest commit:

 $ git tag v1.0

  • git merge: This command is used to merge one branch into another branch in a Git repository. For example, you can use the following command to merge the my-branch branch into the master branch:

$ git merge my-branch

  • git reset: This command is used to reset the state of a Git repository to a previous commit. For example, you can use the following command to reset the repository to the HEAD commit:

$ git reset --hard HEAD

To view or add a comment, sign in

More articles by Ravi Srivastava

  • Monitoring & Observability

    💡 Introduction to Observability Observability is the ability to understand the internal state of a system by analyzing…

  • 🚀 Deploying an Application on GCP Cloud Run: A Step-by-Step Guide

    🚀 Just Published! 🚀 I recently deployed an application on GCP Cloud Run, and I’ve documented the entire process in my…

  • Deploying an AWS Virtual Machine with Terraform: A Step-by-Step Guide

    Introduction Terraform is an open-source infrastructure as code (IaC) tool that allows you to define and provision data…

  • Mastering Docker: Concepts, Architecture, and Installation Guide

    What is Docker? Docker is a containerization platform that provides easy way to containerize your applications, which…

  • Introduction to Containers

    A container is a standard unit of software that packages up code and all its dependencies so the application runs…

  • Kubernetes Cluster Architecture

    Our Kubernetes cluster is structured into two main sections: Master Node (Control Plane) 🖥️ API Server 🛠️ Scheduler…

    1 Comment
  • Summary Zero to Hero Batch-6, Day-4!

    🚀 Hello Connections, TWS-Community, and Techies! Excited to share insights from Zero to Hero Batch-6, Day-4. Today's…

  • 90DaysOfDevops

    Day-3 Task To view what's written in a file. There are 3 ways to view what's written in a file.

  • Day-2 Task: Basic Linux Commands

    Check your present working directory. Command: pwd 2.

  • Introduction-Day1

    What is DevOps? Its not a method or technology, its a Culture in which you need set of practices, principles that aim…

Others also viewed

Explore content categories