Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»GIT»How to Remove Untracked Files from Local Git Repository

    How to Remove Untracked Files from Local Git Repository

    By RahulApril 3, 20192 Mins Read

    What are Untracked Files – All the files and directories, which is created locally and have not been added to the git repository ever.

    Advertisement

    Sometimes you may need to delete these untracked files from your code. These files can be some temporarily created files in an application. Use the below commands to list all untracked files and delete them from the code base.

    List Untracked Files

    First list all the untracked files using the following commands. This is the list of files which will be deleted. This is to make sure that you are not deleting any useful files.

    git clean -f -n
    

    Remove Untracked Files

    All the files listed in above output will be deleted completely from the system. You can’t recover these files back. Check all files listed above and if found any useful files add them in repository first. After confirming that all listed files are not useful, now execute the following command to delete them.

    git clean -f
    

    Remove Untracked Directories

    Above command will delete all untracked files only but not directory. So if you want to remove untracked directories also, use the following commands. The first command will list untracked files and directories and the second command will delete them.

    git clean -f -d -n      # List untracked files and directories 
    git clean -f -d       # Remove untracked files and directories 
    

    See the git-clean docs for more information.

    git Repository untracked files
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Git Change Remote URL: How to

    Git Change Remote URL in Local Repository

    Git Change Remote URL to SSH (from HTTPS)

    How to Create Branch in Git Repository

    View 2 Comments

    2 Comments

    1. BFooster on September 20, 2017 8:35 pm

      Worked great, thanks!

      Reply
    2. Lekha on July 17, 2017 8:03 pm

      v useful. Thanks

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Split Large Archives in Linux using the Command Line
    • System.out.println() Method in Java: A Beginner’s Guide
    • Split Command in Linux With Examples (Split Large Files)
    • Test Your Internet Speed from the Linux Terminal
    • 11 Practical Example of cat Command in Linux
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.