How to Reset a GitHub Repository and Start Fresh: Step-by-Step Guide
How to Reset a GitHub Repository and Start Fresh: Step-by-Step Guide
If you want to completely remove all files and commits from the repository while keeping the repository itself, you can follow these steps:
Steps to remove all files and commits from a GitHub repository:
- Clone the repository locally & open your terminal and run:
git clone https://github.com/username/YourProject.gitcd YourProject2. Create an orphan branch: This will create a new branch without any history of commits.
git checkout --orphan new-branch3. Remove all files: Delete all the files from the working directory.
git rm -rf .4. Commit the changes: Make a new commit with the removed files.
git commit --allow-empty -m "Initial clean commit"5. Delete old branches: You need to delete the main or master branch and replace it with the new one.
git branch -D master # or maingit branch -m master # rename 'new-branch' to 'master'6. Force push the changes to GitHub: This will overwrite the repository history on GitHub.
git push --force origin master # or mainThis will delete all files and commits from the GitHub repository, effectively resetting it while keeping the repository intact.
Add new files and code to your repository, follow these steps:
1. Add new files to your project directory:
You can manually create or copy files into the folder on your local machine.
2. Stage the new files for commit:
Once you’ve added or modified files, use the following command to stage them:
git add .This stages all changes, including new files, modified files, and deletions.
3. Commit the changes:
After staging the files, commit them with a meaningful message:
git commit -m "Add new files and code"4. Push the changes to GitHub:
Push the committed changes to the main branch (or whatever your active branch is) on GitHub:
git push origin mainExample Workflow:
If you added a new file index.html, your commands would look like this:
git add index.html # Stage the new file
git commit -m "Added index.html" # Commit the file
git push origin main # Push the changes to GitHubLet me know if you need help with a specific step!
Comments