Notebooks

  • Git

    • Git repo restart options

When you have an old repo that you want to keep around, but you want to start fresh, here are the options and steps to take for the selection that fits best:

  • Option 1 – Nuclear Reset
# Delete everything except .git
rm -rf * .gitignore  # or manually delete files

# Add your new code via command or manually paste it in
cp -r /path/to/new/code/* .

# Create fresh commit
git add .
git commit -m "Initial commit - fresh start"

# Force push to GitHub (overwrites everything)
git push --force origin main
  • Option 2 – Keep History
# Create orphan branch (no history)
git checkout --orphan fresh-start

# Remove all old files from staging
git rm -rf .

# Add your new code
cp -r /path/to/new/code/* .
git add .
git commit -m "Initial commit - fresh start"

# Replace main with this new branch
git branch -D main
git branch -m main

# Force push
git push --force origin main
  • Option 3 – Archive Old
# Tag the old state for reference
git tag archive/old-version
git push origin archive/old-version

# Then do Option 1 or 2
  • Option 4: Delete and Re-create
# In your new code directory
git init
git add .
git commit -m "Initial commit"
git remote add origin git@github.com:yourusername/repo-name.git
git push -u origin main