How do I completely clean a git working directory?

In mercurial, I am used to being able to do hg up 00 to completely clean out the working directory.

This resets the working directory to it’s state immediately after having performed the hg init.

  • What exactly is a content level merge?
  • “src refspec does not match” and “failed to push some refs” errors on git push
  • Does Git allow me to write my next commit message gradually during developing?
  • Git repository with multiple users on Ubuntu
  • Git: How to get the name of checked out tag when 2/more tags on same commit
  • How to specify a git tag when in the configuration of the SCM Maven plugin?
  • Is there any equivalent in git?

    Note that hg up 00 is not the same as hg up 0, which updates to the first revision committed, instead it is equivalent to hg up null, just a couple of characters shorter to type. *8′)

    Also note that I don’t want to just do an rm -rf * in the root of the git working directory, as then git status will show all of the files as having been removed. I just want to update the repository to it’s state prior to the first commit. Alas my searches through the web and the git manuals haven’t furnished me with the info I need to work out how to do it in git.

    As background, I want to leave the repository in place so that I can easily checkout a different commit later. One reason I want to do this is that I have a very large repository (actually a git svn repo) and I don’t want to have to ever have to re-clone it again (it took days to complete and you aren’t supposed to clone a gitsvn repo). I do want to be able to free up the space taken by the working copy when I don’t need it though.

  • Git- archive old commits
  • Composer - Forked Laravel 4.2 not installing
  • How can I start a clean branch with no ancestry, then commit files progressively?
  • Git rebase - commit select in fork-point mode
  • Apply a command to all commits
  • Unpacker error Git-pushing from bare repo to staging server
  • 3 Solutions collect form web for “How do I completely clean a git working directory?”

    The equivalent of the null revision is called bare repository in git.
    This search gives a rough overview of the topic, different ways of converting a non bare into a bare repo can be found here.

    Unlike hg, there is no easy way to switch between a bare and a non-bare repository. Also you should not push into a non-bare repository, as a push will change the index of git, but does not update the working tree. See Working with git from 2 laptops with no bare repo for details.

    This seems like an unusual thing to want to do, git branches start with an initial commit that is usually non-empty. You can’t “checkout” or “reset” to before this initial commit with usual git commands.

    You can reset the currently checkout branch to an “uncreated” state ready for a new initial commit with this command.

    git updated-ref -d "$(git symbolic-ref HEAD)"
    

    This deletes the currently checked out branch.

    You can then remove all files from the index with this command (assuming that you are at the root of your repository).

    git rm -r --cached .
    

    You may need a -f switch if you have unstaged changes.

    Finally you can clean all files from your working tree with this command. Warning: potentially dangerous.

    git clean -fd # WARNING, dangerous
    

    These are solutions that come to my mind:

    1- You can remove .git directory from your working directory and there will be no git repository in your working directory.

    2- You can reset to initial commit(the initial commit will still remain) by issuing:

    git reset --hard `git rev-list HEAD | tail -n 1`
    
    Git Baby is a git and github fan, let's start git clone.