Open In App
Related Articles

Essential Git Commands

Improve Article
Save Article
Like Article

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


  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


  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


  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


  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


  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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 22 Nov, 2021
Like Article
Save Article
Similar Reads