Shamim Fahad
Shamim Fahad

Reputation: 130

Move all files from master to another branch in Git

I started working on a new project and from the beginning I pushed all my commits to master. But now I think I should've used another branch for development and stored my code there and only have the production build in my master.

Is there any way I can move all my files from master to a new branch?

Upvotes: 1

Views: 6672

Answers (1)

Shay Nehmad
Shay Nehmad

Reputation: 1161

Yes.

Create a branch on the current commit using git branch <whatever>. Then, run git log, and identify which commit is the latest "production" version (probably where you started working). git checkout that commit, and then git branch -f master to make the local master branch point there, and git push -f origin master to update the origin. If you work collaboratively with other people on this repository make sure to update them - force pushing is a destructive action and might cause issues, see this SO question.

Upvotes: 5

Related Questions