## The problem
You've added large files into your [[Git]] repository, inadvertently increasing the size of your repo and potentially preventing you from pushing the changes to a remote repository (if you're using a service like [[GitHub]]).
## Preventing the issue
The best way to avoid this while still keeping the large files locally in your repo is to [[Ignoring files in Git|modify .gitignore]] to exclude the files or directory from being tracked.
## Fixing the issue
### Use [[Fork (app)]]
Honestly, using Fork is probably the easiest way to get around this, if you haven't made any important changes after you committed the large file.
Go through your history to find the last commit where your repo was in a good state.
Right click it, and then click "Reset 'master' to here".
### Rewriting previous commits including large files
Setting `.gitignore` will not work if you've already made commits that included those files. Instead, you need to run this command to completely remove the files even from the previous commits, while maintaining the current state of your repo.
```shell
git filter-branch --index-filter \
'git rm -rf --cached --ignore-unmatch assets/Tokens' -- \
--all
```
This will take a long time. Run a `git status` after it's done executing:
```shell
nic@sopirulino dmb-obsidian % git status
On branch master
Your branch and 'origin/master' have diverged,
and have 998 and 976 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean
```
The output above prompts you to do a `git pull`, which will likely fail with merge conflicts as the contents of the remote is now different from what you have locally.
### Updating your repo
### Merge but take local changes over remote
If you know you want to use the changes that you have locally, use this command:
```shell
git pull -Xours
```
This will pull everything from the remote, but while maintaining the state you have locally in cases where the two diverge. This is handy if you know that your copy is more updated. Effectively, this command merges the two branches (remote and local).
A problem with this is that it may result in duplicate content within files, or duplicate files. For example, if the remote contains a file and the local machine has the same contents in a different filename, two files will kept, with identical contents.
### Force push
The best thing to do is do a force push:
```shell
git push -f
```
This will override everything with the current local contents, which is usually going to yield the best results.
## References
- [Stackoverflow](https://stackoverflow.com/questions/6650215/how-to-keep-the-local-file-or-the-remote-file-during-merge-using-git-and-the-com)
- [Simme's notes](https://notes.simme.dev/Deep+cleaning+Git+Repositories)