Skip to the content.

20 Super Useful Git Commands

1.git config

Configures user information used across all local repositories.

NOTE: There shouldn’t be any space between “user.” and “name”. Similarly no space between “user.” and “email”.

2.git init

Initialises an existing directory as Git repository.

3.git clone

Retrieves an entire repository from a hosted location via a valid Git URL.

4.git add

Add a file to staging area

5.git rm

Deletes the file from project and stages the removal for commit.

6.git mv

Changes an existing file path and stages the move.

7.git commit

Commits the staged contents as a new commit snapshot.

8.git branch

List, Create or, Delete Branches

List branches

Create a new Branch at the current commit

Delete a Branch

9.git status

Shows the paths of modified files in working directory.

10.git diff

Show changes between commits.

To see diff of what is changed, but not staged

To see diff of what is staged, but not committed

To see diff between 2 branches

11.git log

Shows the commit history for the currently active branch

Shows the commits on branchA that are not on branchB

12.git checkout

Switch branches.

Switch to another branch and, check it out into your working directory

Switch to another branch (create if does not exist)

13.git merge

Join 2 or, more development histories together.

14.git fetch

Fetch branches and/or tags from one or more other repositories.

NOTE: You can use git fetch to know the changes done in the remote repo/branch since your last pull.

15.git pull

Fetch and merge any commits from the tracking remote branch.

16.git push

Transmit local branch commits to the remote repository branch.

17.git rebase

Applies any commits of current branch ahead of specified one.

18.git revert

Reverts some existing commits.

19.git reset

Resets current HEAD to the specified state.

Unstages a file while retaining the changes in working directory

Clears staging area, rewrite working tree from specified commit

20.git stash

Temporarily stores modified, tracked files in order to change branches

Save modified and staged changes

List StackOrder of stashed file changes

Write working from top

Discard the changes from top

Ref: swapnakpanda - X