How to Untrack Files From Git Temporarily – Linux Hint

Developers often encounter a situation where they do not want to commit all created and modified project files and temporarily ignore them from the staging area. In addition, they want to keep these changes without updating the repository. In this situation, you need to temporarily untrace these files. More specifically, the commands “$ git rm -cached” and “$ git update-index” can be useful for this corresponding purpose.

This post discusses

: Method 1: How to untrack Git files temporarily using “git

  • rm -cached” command? Method 2: How to crawl git files temporarily using “git update-index” command?

Now, move towards the detail of the methods mentioned above!

Method 1: How to untrace git files temporarily using “git rm -cached” command? The “$

git rm –

cached” command can temporarily delete the specified file from the staging area and untrace it. To implement this operation for better understanding, follow the steps below.

Step 1: Move to local repository

First, navigate to the particular Git repository by running the command “cd

“: <img src="https://linuxhint.com/wp-content/uploads/2022/11/How-to-Untrack-Files-From-Git-Temporarily-1.png"

alt=”” />

Step 2: Content List

Run the following command to view the list of the current contents of the

repository:

<img

src=”https://linuxhint.com/wp-content/uploads/2022/11/How-to-Untrack-Files-From-Git-Temporarily-2.png” alt=”” /> Step

3: Create

a new

text file To create a new text file in the repository, use the “touch” command

:

Step 4: Provisionalize the file

Next, run the command provided below to add the text file to the staging area:

<img src

=”https://linuxhint.com/wp-content/uploads/2022/11/How-to-Untrack-Files-From-Git-Temporarily-4.png” alt=”” />

Step 5: Temporarily

delete the file from the

staging area Now, delete the file from the staging area by running the “git rm” command along with the “-cached” option ” and the particular file name

:

<img

src=”https://linuxhint.com/wp-content/uploads/2022/11/How-to-Untrack-Files-From-Git-Temporarily-5.png” alt=”” />

Step 6: Check

the status of the repository Run the “

git status.” command to check the status of the repository

:

As you can see, the specified file has been temporarily removed from the staging index:

Let’s move on to the next method to

untrack Git files temporarily.

Method 2: How to uncrawl Git files temporarily using “git update-index” command?

Sometimes, developers don’t want to keep track of all the files created in the staging area and want to ignore them temporarily. To do this, follow the steps below.

Step

1: Ignore particular

file

To start ignoring the desired text file with changes, run the provided command along with the path of the desired

file: Here, the “-

assume-unchanged” option will assume that the file is not changed and will ignore modifications

:

Step 2: Move

to Git repository Now,

navigate to the particular local Git repository using the following

command:

<img src

=”https://linuxhint.com/wp-content/uploads/2022/11/How-to-Untrack-Files-From-Git-Temporarily-8.png” alt=”” />

Step 3: Check the status of

ignored files Now,

to make sure that the specified file is ignored correctly, run the command “git ls-files” with the option “ -v“: Here

, the “h” indicates that the file is

not temporarily crawled from the repository and “H” shows that the file is crawled

:

<img src

=”https://linuxhint.com/wp-content/uploads/2022/11/How-to-Untrack-Files-From-Git-Temporarily-9.png” alt=”” /> Step 4: Return to the

Git root directory Next, return to the Git root directory using the “cd..”

:

<img

src=”https://linuxhint.com/wp-content/uploads/2022/11/How-to-Untrack-Files-From-Git-Temporarily-10.png” alt=”” /> Step 5: Track a

particular ignore

file

After performing the desired operations in the Git repository, trace the ignored file and run the following command along with the “-no-assume-unchanged” option

:

<img

src=”https://linuxhint.com/wp-content/uploads/2022/11/How-to-Untrack-Files-From-Git-Temporarily-11.png” alt=”” /> Step

6: Move to

the Git repository Next,

navigate to the local Git repository using the command provided

:

<img src

=”https://linuxhint.com/wp-content/uploads/2022/11/How-to-Untrack-Files-From-Git-Temporarily-12.png” alt=”” />

Step 7: Check

the current status of the file

Finally, check the status of the previously ignored file: As you can see, the status of

the file highlighted

below is “H“, which indicates that the file has been successfully crawled:

That’s it! We have provided different ways to untrack files from the Git repository temporarily.

Conclusion

Two different commands are used to untrace files from the Git repository, which are the command “$ git rm -cached <file-name>” or “$ git update-index -assume-unchanged <path/to/file>“. To trace the ignored file, the command “$ git update-index -no-assume-unchanged <path/to/file>” can be used. This post illustrated the different commands for untracking files from the Git repository temporarily.