Chat Zalo Chat Messenger Phone Number Đăng nhập
How to Untrack Files From Git Temporarily - Linux Hint

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 repository content

:

<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

:

How to Untrack Files From Git Temporarily 3

Step 4: Staging the file

Untrack Then run the command provided below to add

the text file to the staging area:

How to Untrack Files From Git Temporarily 4

Step 5: Temporarily

delete the file from the staging area

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

:

How to Untrack Files From Git Temporarily 5

Step 6: Check

the repository status Run the

git status.” command to check the repository status

:

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

How to Untrack Files From Git Temporarily 6

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 has not been changed and ignore modifications

:

How to Untrack Files From Git Temporarily 7

Step 2: Move

to Git repository Now,

navigate to the particular local Git repository using the following

command:

How to Untrack Files From Git Temporarily 8

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 command “h” indicates that the file is

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

:

How to Untrack Files From Git Temporarily 9

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: Crawl 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

:

How to Untrack Files From Git Temporarily 12

Step 7: Check the current status of the file

Lastly, check the above status of the ignored

file:

As you can see, the status of the file highlighted below is “H“, indicating that the file was successfully crawled:

How to Untrack Files From Git Temporarily 13 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.

Contact US