Debug School

Manish Mishra
Manish Mishra

Posted on

Git Commands

Basic commands:

  • to check installed version
    git --version

  • to set user name and email for current repo
    git config "Manish Mishra"

git config ""

  • to list the current configurations for a repo
    git config --list

  • first time to initialize a project (Run inside project Directory)
    git init

  • check status
    git status

  • Git Add - > adds selected changes to staging area
    git add file1 file2

  • Commit without -m it will pop out editor for text message
    git commit
    git commit -m "Your Message"

  • add all changes to stage at once
    git add .

  • add and commit simultaneously
    git commit -a -m "message"

  • to view details about a particular commit
    git show

  • to view commit history
    git log
    git log --oneline

  • rename file
    git mv

  • remove file that is tracked
    git rm

  • remove a file that is not staged or committed (Untracked)
    git clean -fd

  • clone a repo
    git clone

  • pull a repro (pull = fetch + merge)
    git pull

  • add repo link to the local repo
    git remote add origin

  • After adding above , to push to a remote repo
    git push origin

Undoing changes:

  • it will undo all the changes which are done to the file that are unstaged/uncommited
  • it will revert the changes and reflect the changes per current HEAD
    git restore

  • remove file from stage area
    git restore --staged

  • revert creates a new commit to undo the changes as per the commit hash provided

git revert

Git Diff:

-compares staging area and working directory

  • only show unsatged changes
    git diff
    git diff

  • get difference between two commits
    git diff

  • will list changes between tips of the two branch
    git diff


  • view existing branches in current repo
    git branch

  • should not include spaces

  • just makes the branch

  • does not switch to the branch (Head does not change)
    git branch

-checkout the branch
git checkout -b
git checkout

  • to list remote tracking branch git branch -r


  • switch to the main branch, and use below git merge e.g: if you want feature branch to be merged in main git checkout main git merge feature

based on the commit histories; after creation of the feature branch from main: there are multiple cases of merge:
Fast-Forward: simplest type
In this the feature branch have single of multiple commit since creating the branch while the master branch does not have any commit in that period.

merge particular feature from feature branch to be merged into master

git cherry-pick


  • creates a tag and attached it to the current commit
    git tag

  • to tag a particular commit
    git tag

  • delete tag

git tag -d

  • push all tags

git push --tags

  • single tag

git push origin

  • get details of tag

git show

Top comments (0)