Some useful GIT commands

Nishit Ranjan
2 min readMay 2, 2020
  1. git log -n: Will show the n most recent commits
  2. git branch — merged master: Prints the branches merged into master
  3. git branch — merged lists: Prints the branches merged into HEAD
  4. git branch — no-merged: Prints branches that have not been merged(By default this allows only to local branches. -a flag for all branches and -r flag for remote branches).
  5. git stash drop: Will remove the latest added stash
  6. git stash drop <stashname> : Remove a specific stash
  7. git config — list: Prints all the git configuration settings
  8. git checkout -b <branch_name> :Creates a new branch in GIT
  9. git branch -d <branch_name> : Deletes a branch
  10. git diff: Displays differences between 2 versions or between working directory or between index and most recent commit.
  11. git rerere: Stands for “reuse recorded resolution”. By using rerere, GIT remembers how we’v resolved a hunk conflict.
  12. git diff -cached: Displays the differences between working directory and the most recent commit
  13. git status: Shows the status of working tree.
  14. git rm: Removes a file from the working tree and the index.
  15. git rm -r : to recursively remove all files from a leading directory.
  16. git stash apply: Brings back the unfinished work
  17. git stash apply <stashname>: Applies the indicated stash
  18. git reset: Reverses the action of git add
  19. git commit — ammend: Changes the commit message
  20. git init -bare : Creates a bare repository in GIT.
  21. git remote add <Remote Repo URL> :adds the local repo on Git Server.
  22. git clean: Recursively cleans the working tree.
  23. git clean -x: Ignored files are removed
  24. git diff <commit#1> <commit#2>: Prints differences between two commits.
  25. git branch -v: Shows latest commit associated with each branch.
  26. git grep: Allows us to search for a string or regular expression in any committed tree or the working directory.
  27. git blame -L <file_name>: Displays commit and name of a person responsible for making change in that line.
  28. git gc: Performs garbage collection of repository. Cleans unnecessary files.
  29. git archive: Creates a tar or zip file including the contents of single tree from local repository.
  30. git fsck: Performs integrity check of the Git file system.
  31. git prune: Used to remove objects that are no longer pointed to by any object in any reachable branch.
  32. git ls -tree: Shows a tree object. Includes name of each item and SHA-1 value of blob or tree that it points to.
    e.g., git ls-tree master
  33. git cat -file: Used to view the type of an object through SHA-1 value.
  34. git show: Shows information about a git object.
    e.g., git show commit 6d-d2c056e96b4
    Author: User <john@doe.com>
    Date: Thu Jul 6 09…….and so on
  35. git tag: Tags a specific commit to a human readable handle that will never move
    git tag -a v5.0 -m ‘version 5.0 tag’

--

--

Nishit Ranjan
0 Followers

I am a software engineer. I specialize in JavaScript, React.js, NodeJS, Docker and Kubernetes.