The Wayback Machine - https://web.archive.org/web/20240927190502/https://www.geeksforgeeks.org/essential-git-commands/
Open In App

Essential Git Commands

Last Updated : 22 Nov, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

When it comes to commands, there come numerous commands in a software developer head or one that is mastering over git but even only a few of them are used frequently in the enterprising domains that are used frequently by developers in order to boost workflow. So here we will be listing a couple of them prior to dividing them into categories in order to perceive real quick. These commands are peculiar curated allowing to go from scratch from creating a new repository and playing further creating branches, merging to master branch.

Categories are as follows:

  • To create
  • To make local changes
  • To commit history
  • Branches and tags
  • To update and publish
  • To merge and reuse
  • To undo

Let us do define commands that do fall under these categories that are listed below as follows:  

Type 1: CREATE

  1. Clone an existing repository: git clone
  2. Create a new local repository: git init

Type 2: LOCAL CHANGES

  1. Changed files in your working directory: git status
  2. Changes to tracked files: git diff
  3. Add all current changes to the next commit: git add
  4. Add some changes to the next commit: git add -p
  5. Commit all local changes In tracked files: git commit -a
  6. Commit previously staged changes: git commit
  7. Change the last commit: git commit –amend

Type 3: COMMIT HISTORY

  1. Show all commits. starting with newest: git log
  2. Show changes over time for a specific file: git log -p
  3. Who changed what and when in: git blame

Type 4: BRANCHES & TAGS

  1. List all existing branches: git branch -av
  2. Switch HEAD branch: git checkout
  3. Create a new branch based on your current HEAD: git branch
  4. Create a new tracking branch based on a remote branch: git checkout – -track
  5. Delete a local branch: git branch -d
  6. Mark the current commit with a tag: git tag

Type 5: UPDATE and PUBLISH

  1. List all currently configured remotes: git remote -v
  2. Show Information about a remote: git remote show
  3. Add new remote repository, named remote: git remote add
  4. Download all changes from but don’t integrate into HEAD: git fetch
  5. Download changes and directly merge/integrate into HEAD: git pull
  6. Publish local changes on a remote: git push
  7. Delete a branch on the remote: git branch -dr
  8. Publish your tags: git push –tags

Type 6: MERGE & REUSE

  1. Merge into your current HEAD: git merge
  2. Rebase your current HEAD onto git rebase
  3. Abort a rebase: git rebase – -abort
  4. Continue a rebase after resolving conflicts: git rebase – -continue
  5. Use your configured merge tool to solve conflicts: git mergetool
  6. Use your editor to manually solve conflicts and (after resolving) mark tile as resolved: git add, git rm

Type 7: UNDO

  1. Discard all local changes in your working directory: git reset -hard HEAD
  2. Discard local changes in a specific file: git checkout HEAD
  3. Revert a commit (by producing a new commit with contrary changes): git revert
  4. Reset your HEAD pointer to a previous commit and discard all changes since then: git reset –hard
  5. Preserve all changes as unstaged changes: git reset
  6. Preserve uncommitted local changes: git reset – – keep

Previous Article
Next Article

Similar Reads

Difference Between Git remote prune, Git prune and Git fetch --prune
Git is a version control system that helps developers manage and track changes in their codebase. Among its many commands, git remote prune, git prune, and git fetch --prune are essential for maintaining a clean and organized repository. This article will explain the differences between these commands, their syntax, uses, and provide examples to il
4 min read
Basic Git Commands with Examples
Nowadays open source contribution is on the peak. It's getting so much popular among students and there are also some open-source programs and competitions to learn so much about development. Open source is a great way to learn and make a better community. There are so many organizations where one can contribute and learn. For that one have to know
3 min read
Simple and Concise Git Commands That Every Software Developer Should know
As developer git is the most useful arena which is not operated directly so do we have git commands that become very crucial that one should know after having git installed in the local system. if not you must download git from here Download Git. If you need any help with the further installation process. So, Now let's start with the basic commands
4 min read
Automating some git commands with Python
Git is a powerful version control system that developers widely use to manage their code. However, managing Git repositories can be a tedious task, especially when working with multiple branches and commits. Fortunately, Git's command-line interface can be automated using Python, making it easier to manage your code and automate common tasks. One p
3 min read
How to Use Git Commands in Android Studio Terminal?
Android Studio is the official IDE (Integrated Development Environment) for Android app development and it is based on JetBrains’ IntelliJ IDEA software. Git is a Distributed Version Control System. It is used in Software Development. Git was developed by Linus Torvalds in the year 2005 to manage the development of the Linux Kernel Need of Git Git
2 min read
How to Push Folders From Local PC to GitHub using Git Commands?
Git offers a powerful command-line interface for managing code repositories, understanding how to push folders from your local PC to GitHub repositories using Git commands can enhance your workflow and streamline the process of sharing code with collaborators or deploying projects. In this article, we'll see the step-by-step process of pushing fold
2 min read
All Git Commands You Should Know
Git is a distributed version control system (VCS) that allows multiple developers to work on a project at a time, giving the possibility of changing each other's work based on requests and authorizations. Created by Linus Torvalds in 2005 for the development of the Linux kernel, Git has since become the most widely used version control system in th
8 min read
How to Dry Run Git Commands?
Git is used for version control in software development. Understanding the effects of Git commands before executing them can help prevent mistakes and ensure that your repository remains in a good state. This is where "dry running" Git commands become incredibly useful. A dry run simulates the execution of a command without making any changes, allo
3 min read
Top 15 Git Commands to Become a Pro Developer [2024]
Git is a distributed version control system and open-source software used by developers to manage different versions of source code by tracking changes in files. It is used by developers to work together on the same project from anywhere. Whether you are a professional developer or just starting your coding journey, Git is essential for becoming a
8 min read
Useful Git Commands and Basic Concepts
Git is a powerful version control system widely used in software development to track changes, collaborate on projects, and manage code efficiently. Understanding the basic concepts and commands in Git is important for any developer. This article will cover the fundamental concepts and some of the most Useful Git Commands and Basic Concepts to help
5 min read
How to Generate Public SSH or GPG Keys Using Git Commands?
Generating public SSH or GPG keys is important for securing your Git operations and ensuring the authenticity of your commits. In this guide, we'll walk you through the process of generating these keys using Git commands, making it easy to track along and understand. What Are SSH Keys?SSH (Secure Shell) keys are a pair of cryptographic keys used to
2 min read
How to Use Git Shell Commands?
Git is a powerful version control system that is important for managing source code in modern software development. While there are many graphical user interfaces (GUIs) available for Git, mastering Git shell commands can significantly enhance your productivity and control over your repositories. This article provides an overview of essential Git s
3 min read
Top 12 Git Commands for Every Developer
Git is a distributed version control system and open-source software. It enables developers to manage many versions of a source code with ease. You can use it to figure out who did what, when, and why. Git has become a must-have tool for any developer nowadays, and knowing Git commands is required for developers to fully utilize Git. There are hund
9 min read
Git - git-show Command Line Utility
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git relies on the basis of distributed development of software where more than one developer may have access to the source code of a specific application and can modify changes to it that may be
3 min read
Git LFS: Managing Large Files in Git Repositories
Git, undoubtedly one of the most popular version control systems, is widely used for managing source code in software development projects. However, one of its limitations is its handling of large files. Traditional Git repositories struggle to efficiently manage large files, leading to bloated repositories and slow performance. This is where Git L
4 min read
Git Subtree vs. Git Submodule
Git Subtree and Git Submodule are both mechanisms in Git that allow you to incorporate external repositories into your own repository. They provide a way to manage dependencies and include code from other projects while keeping your repository organized and maintainable. Git Subtree: Git Subtree allows you to insert a separate repository as a subdi
4 min read
How to Set Up Git Using Git Config?
Git is a powerful version control system that helps developers manage and track changes in their code. Setting up Git correctly is important for maintaining an organized and efficient workflow. In this article, we'll walk you through the process of setting up Git using the git config command. PrerequisitesBefore we dive into the setup process, make
3 min read
How To Exit Git Log or Git Diff?
When working with Git, the git log and git diff commands are important for viewing commit history and changes between commits, respectively. However, if you're new to Git, you might find yourself stuck in these views, unsure how to exit. This article will guide you through the steps to exit git log or git diff, ensuring a smooth experience while na
2 min read
Difference between “git add -A” and “git add”
When working with Git, the git add command is used to move changes from your working directory to the staging area. However, there are different options and flags that can be used with git add, such as -A, which might lead to some confusion. In this article, we'll explore the differences between git add -A and git add. 1. Git add- CommandThe git ad
2 min read
Git - Difference Between Git Revert, Checkout and Reset
Git offers a range of commands to manage and manipulate your codebase. Among these commands, git revert, git checkout, and git reset are frequently used for different purposes. Understanding the differences between these commands is important for effective version control. In this article, we'll explore the functionalities and use cases of git reve
6 min read
How to Fix Git Error "Unable to create '/path/my_project/.git/index.lock'"?
The Git error "Unable to create '/path/my_project/.git/index.lock'" typically occurs when Git is unable to create or write to the index.lock file. This file is used to prevent simultaneous processes from modifying the repository, which could lead to corruption. Table of Content Remove the Lock File ManuallyUse Git Command to Remove the Lock FileRes
2 min read
Difference Between "git commit" and "git push"?
Git commit and git push are two essential commands you'll use a lot when working with Git. even their frequent use together, they have different functions. In order to help you understand when and how to use these two commands effectively in your version control workflow, this article will break down their differences. What is git commit?git commit
2 min read
Difference Between Git Fetch and Git Pull
Understanding the difference between git fetch and git pull is important for effective version control in Git. Git Fetch and Git Pull are two important commands in Git that help in managing remote repositories. While both commands involve retrieving data from remote repositories, they serve distinct purposes and are used in different contexts. In t
5 min read
Git - git prune
Git prune is used to remove the unreachable objects and clear up the local repository. Git is a powerful version control system that helps developers manage their code efficiently. However, as your project evolves, you may accumulate unnecessary data that clutters your repository. This is where git prune comes in view. Table of Content What is git
6 min read
Git For Non-Developers: How Different Industries Are Adopting Git?
While Git is widely recognized for its role in software development, it's increasingly being adopted by non-developers across various industries. This shift is driven by the growing need for version control, collaboration, and efficient project management in fields like marketing, design, data science, education, and even legal and finance sectors.
8 min read
Difference Between Git Push Origin and Git Push Origin Master
Understanding the difference between git push origin and git push origin master is important for efficient version control in Git. These commands are used to upload changes from your local repository to a remote repository, but they function differently. This article will explain these differences, how each command works, and when to use them. What
3 min read
Git vs. Other Version Control Systems: Why Git Stands Out?
Version control systems (VCS) are an essential tool for developers, enabling them to track changes, collaborate on projects, and manage codebases efficiently. Among the various VCS options available, Git has emerged as the dominant choice, used by millions of developers and organizations worldwide. While other systems like Subversion (SVN), Mercuri
8 min read
An Ultimate Guide to Git and Github
Highlights of the article: Introduction to GitGit Repository StructureGithubAccessing Github central repository via HTTPS or sshWorking with git - Important Git commandsIntroduction to Git For installation purposes on ubuntu, you can refer to this article: How to Install, Configure and Use GIT on Ubuntu? Git is a distributed version control system.
8 min read
Git - Changing History
Git provides a very important option of altering the commit history. As the master of git, you can control and make it function according to you. Git gives you the authority to change the order of commits, change messages, remove commits entirely. Moreover, it also allows you to manage the project's history. However, it is advisable to commit the w
3 min read
Introduction to Git Branch
Branching means diverging from the mainline and continue to work separately without messing with the mainline. Nearly every VCS has some form of branch support. In Git, a branch is simply a reference to the commit, where the following commits will be attached. Git vs SVN: In recent years, the use of git has risen tremendously. Unlike SVN, git allow
3 min read
Article Tags :