Some useful GIT commands
- git log -n: Will show the n most recent commits
- git branch — merged master: Prints the branches merged into master
- git branch — merged lists: Prints the branches merged into HEAD
- 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).
- git stash drop: Will remove the latest added stash
- git stash drop <stashname> : Remove a specific stash
- git config — list: Prints all the git configuration settings
- git checkout -b <branch_name> :Creates a new branch in GIT
- git branch -d <branch_name> : Deletes a branch
- git diff: Displays differences between 2 versions or between working directory or between index and most recent commit.
- git rerere: Stands for “reuse recorded resolution”. By using rerere, GIT remembers how we’v resolved a hunk conflict.
- git diff -cached: Displays the differences between working directory and the most recent commit
- git status: Shows the status of working tree.
- git rm: Removes a file from the working tree and the index.
- git rm -r : to recursively remove all files from a leading directory.
- git stash apply: Brings back the unfinished work
- git stash apply <stashname>: Applies the indicated stash
- git reset: Reverses the action of git add
- git commit — ammend: Changes the commit message
- git init -bare : Creates a bare repository in GIT.
- git remote add <Remote Repo URL> :adds the local repo on Git Server.
- git clean: Recursively cleans the working tree.
- git clean -x: Ignored files are removed
- git diff <commit#1> <commit#2>: Prints differences between two commits.
- git branch -v: Shows latest commit associated with each branch.
- git grep: Allows us to search for a string or regular expression in any committed tree or the working directory.
- git blame -L <file_name>: Displays commit and name of a person responsible for making change in that line.
- git gc: Performs garbage collection of repository. Cleans unnecessary files.
- git archive: Creates a tar or zip file including the contents of single tree from local repository.
- git fsck: Performs integrity check of the Git file system.
- git prune: Used to remove objects that are no longer pointed to by any object in any reachable branch.
- 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
- git cat -file: Used to view the type of an object through SHA-1 value.
- git show: Shows information about a git object.
e.g., git show commit 6d-d2c056e96b4
Author: User <firstname.lastname@example.org>
Date: Thu Jul 6 09…….and so on
- 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’