Useful Git commands

Remove all local changes 

Sometimes one just want's to start over after playing around with the code. Thanks to the Git revision control it's quite easy to remove local changes. 

There are three possible types of files when we make local changes:

  1. Staged Tracked files
  2. Unstaged Tracked files
  3. Unstaged UnTracked file

To remove all the changes use the following commands:

git clean -f -d -x
git reset --hard
  • git clean -f -d -x
    Removes Unstaged Untracked files (Type 3)
    -f, --force If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f, -n or -i.
    -d Remove untracked directories in addition to untracked files.
    -x This allows removing ignored as well as non-ignored files.
    -X Remove only files ignored by Git. 
    -n, --dry-run Don't actually remove anything, just show what would be done.

  • git reset --hard
    Removes Staged Tracked and UnStaged Tracked files (Type 1 and 2)

Print Email

Add comment


Security code
Refresh