A little help needed with Git!

Using Obsidian Git, I inadvertently tried to push a > 600mb attachment folder (along with usual changes of some “.md” files that needed to be backed-up). It would have taken forever so I just killed the process while Obsidian Git was pushing (probably worst idea ever).

Then, on Github, I added a .gitignore file with the path of attachment folder to be excluded and pulled the changes to my local repo using command line.

Now, how can I properly exclude this “attachment” folder since it was already committed to my local repo ?

I was thinking of something like git rm ATTACHMENT_PATH, but wouldn’t Obsidian Git try to add back this folder each times it tries to push ? Will the .gitignore file prevent this after the git rm ?

I hope this is not too confuse, I’m new to git.

Any help is welcome !

  • How to ignore previously tracked files.

  • Before doing this process, be sure to commit all changes, including the new .gitignore.

  • To clear the repository use the following command:

    • git rm -r --cached .
      • rm is the remove command
      • -r allows for recursive removal
      • --cached removes files from the index only. Local files are untouched.
      • . indicates that all files will be made untracked. A specific file name can be given to untrack that file only.
  • Add everything back to the repository:

    • git add .
  • Commit:

    • git commit
  • After this process, Git should start to ignore files listed in the .gitignore. It will not remove the files from the directory, just the Git index.

Thank you. Well, after doing this procedure and trying to push, even if a diff does not show the files of the attachment folder, for an unknown reason it still tries to push them…

I think it’s due to the fact that attachment folder was not added in the latest commit but in earlier commit, thus those need to be cleaned too ? Not sure yet how to proceed.

Or maybe aborting the push was not a good idea ?

Make sure your .gitignore is correct for ignoring a directory.

Have you had any luck with this?

Hello @jwl,

I think my problem had to do with cleaning that big folder from my history of commit (see Removing sensitive data from a repository - GitHub Docs).

Unfortunately, I typed too many Github command that I don’t master enough, and at some points it became a mess so that it was much easier to start repo from scratch.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.