Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»GIT»How to Remove Untracked Files from Local Git Repository

    How to Remove Untracked Files from Local Git Repository

    RahulBy RahulNovember 21, 20152 Mins ReadUpdated:April 3, 2019

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

    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
    Previous ArticleHow to Install FFmpeg on CentOS/RHEL 7/6
    Next Article Red Hat 8.0 Beta Released

    Related Posts

    How To Add a Git Remote Repository

    3 Mins Read

    How to Git Reset to Head

    Updated:November 3, 20213 Mins Read

    How to Delete a File on Git

    3 Mins Read

    How to Git Stash Changes

    Updated:October 29, 20213 Mins Read

    How to delete Git tags

    Updated:October 25, 20211 Min Read

    How to Create Git tags

    Updated:October 25, 20212 Mins Read

    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

    Recent Posts
    • How to Install Sublime Text 4 on Ubuntu 22.04
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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