Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github, push a new project in place of an old one

I have an iOS project setup to on github and over the past few days I have started to realize that I need to refactor most of my code. I build the project not abiding by many of the basics of MVC and now want to go back and fix everything.

The main issue is that the project is large enough where refactoring will be a massive pain. Is there anyway that I can start a new project, build it to the place the current one is at (obviously with some major design changes) and push that up to github into the same branch instead of the original project? If this is not clear please let me know.

like image 814
Firo Avatar asked Dec 12 '22 18:12

Firo


2 Answers

I would expand on the given answers a bit, given your desire to keep your old history. In this case, you don't want to start a new repo; you just want to "manhandle" the old one, clearing out old data and adding new. You can accomplish this with the following steps:

  1. cd into the root of your project dir.
  2. Remove everything you don't want from the filesystem. Be careful to leave the .git/ folder. That's your repository's previous history.
  3. Add whatever new stuff you want (new Xcode project, directory structure, etc.).
  4. When you're ready to commit, git status is going to show you quite a mess (the size of which will depend upon how many files you used to have) of deletions and additions. That's okay, this is where you take a broad brush to all of these entries, with git add --all .. This will stage everything in your repo, deletions, new additions, all of it.
  5. git commit -m "My new beginning".
  6. git push origin myBranch --force

Voila! Your repository is completely made over, with the added bonus of retaining your previous history.

like image 103
KevinH Avatar answered Dec 27 '22 12:12

KevinH


You can. Just create your new project and type the following commands into a command line interface (cmd in Windows, terminal in linux).

cd /path/to/project
git remote add origin [email protected]:username/repo.git
git push origin master --force

That should do it.

like image 25
Demortes Avatar answered Dec 27 '22 13:12

Demortes