How to remove a file from git without removing it from your file system?



How to remove a file from git without removing it from your file system?..

Answer / Amol Kumar

To remove a file from Git without deleting it from your file system, follow these steps:
1. Remove the file from your working directory.
2. Add the file to the .gitignore file to prevent it from being added back to Git.
3. Run `git rm --cached <file>` to remove the file from Git's index without affecting the file in your working directory.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Git Interview Questions

What are the different ways you can refer to a commit?

1 Answers  


What is another option for merging in git?

1 Answers  


What is rebasing syntax in git?

1 Answers  


What is the difference between git pull and git fetch?

1 Answers  


What is git Is-tree?

1 Answers  


How do you find a list of files that have changed in a particular commit?

1 Answers  


How to rebase master in git?

1 Answers  


What is a repository in GIT?

1 Answers  


What is git bisect and what is its purpose?

1 Answers  


What is Subgit? Why to use Subgit?

1 Answers  


What is the difference between the ‘git diff ’and ‘git status’?

1 Answers  


How many heads can be created in a repository?

1 Answers  


Categories