Created
July 3, 2023 15:21
-
-
Save zainabnazari/7336dc89b8af38ebd11b187a1bf129d5 to your computer and use it in GitHub Desktop.
If you push a large file or folder into github and it was rejected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First, make sure you have a backup of your repository or any important files, as this process is irreversible. | |
git rm -r folder_name | |
git commit -m "Remove folder_name from repository" | |
By default, Git retains the history of commits, even for deleted files or folders. | |
To delete the history and make it easier to push the changes, you can use the git filter-branch command. Run the following command: | |
git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch folder_name' --prune-empty --tag-name-filter cat -- --all | |
Once the filter-branch operation completes, the history of the folder will be deleted. However, the commits are still present in your local repository. | |
To remove them completely, you can run the following command: | |
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin | |
finally | |
git push origin --force --all | |
git push origin --force --tags |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment