Bidhya Pokharel
Bidhya Pokharel

Reputation: 57

How to detach a folder from being tracked without deleting any files from it?

I completed MyProject1 and have uploaded it in git in fine way with commits after adding each new features. And now I'm starting MyProject2 and was trying to add the URL for the remote repository. But then I found out that I had mistakenly added the URL in Documents instead of MyProject1 folder because of which MyProject2 folder is also being tracked in MyProject1. And I'm not being able to add URL to MyProject2 but instead facing merge issues.

Is there any way to detach the track from my Document folder without deleting any of my files from Documents. Structure is this way(I'm using Linux):

Documents (And inside Documents there is:)

  1. MyProject1
  2. MyProject2
  3. And other folders which are also being tracked.

Upvotes: 0

Views: 98

Answers (2)

aleksanderwalczuk
aleksanderwalczuk

Reputation: 3

Best way:

Create a .gitignore file following @Vinayagam R

Ignore file locally

Those methods won't affect other contributors working on the same remote repository:

Use update-index:

If you want to stop tracking a file at certian point.

git update-index --assume-unchanged yourDirectoryName

--assume-unchanged is the flag which means the files should not change locally. In other words, it is used when ignore files that you do not need to change locally (or should not change).

To revert it use update-index --no-assume-unchanged yourDirectoryName

Using .exclude

In your working directory edit .git/info/exclude

Upvotes: 0

Vinayagam R
Vinayagam R

Reputation: 101

We can manually do it with below steps

  1. create a file .gitignore in base directory.
  2. If MyProject1 and MyProject2 are already part of git tracking, Please run commands
    git rm -r --cached MyProject1/
    git rm -r --cached MyProject2/
  3. Open the file in text editor and add below lines in file MyProject1/ MyProject2/

Upvotes: 1

Related Questions