Home > other >  Creating a new branch for re-initializing the entire project in git
Creating a new branch for re-initializing the entire project in git

Time:11-05

I've been working on a project since a few years ago. Even though that project is still working well, but its logic and base forms need a huge change. A lot of improvements are needed for the project and that's why I decided to recreate that project and start from scratch. I'm using Git to manage my project.

Is it normal to create a new branch (like "re-creation"), then remove all stuff and start rebuilding the project and merge it back to the main/master branch? I think it works, but not sure about the concept because branches are mostly used for creating new features or fixing issues, not to rebuilding the entire project.

My main concern about improving the current project and avoiding rebuilding it is that there are no tests at all and Dirty Codes everywhere.

CodePudding user response:

I feel like you need to deal with two things:

  1. Create a fork of your current repository. This will be a copy with a new "starting point".

You can create a fork of your own local repo. The idea is so you can start working on a copy of an existing repo, starting at the point of the fork, then make your own changes independent of the work being done on the original repo.

I started a sample repo here:

/c/code/testing

# created a new folder
git@local testing
$ mkdir repoA
$ cd repoA

# in that folder
git@local repoA
$ git status
fatal: not a git repository (or any of the parent directories): .git

# create new repo
git@local repoA
$ git init
Initialized empty Git repository in C:/code/testing/repoA/.git/

# check status
git@local repoA (main)
$ git status
On branch main

No commits yet

nothing to commit (create/copy files and use "git add" to track)

# go back to parent folder
git@local repoA (main)
$ cd ../

git@local testing
$ ls -l
total 0
drwxr-xr-x 1 adrian.moreno 197121 0 Nov  3 17:04 repoA/

# clone (fork) my local repo to a new one.
git@local testing
$ git clone repoA repoB
Cloning into 'repoB'...
warning: You appear to have cloned an empty repository.
done.

# Now I have two repos. 
# repoA is forked from the last commit on repoA.
git@local testing
$ ls -l
total 0
drwxr-xr-x 1 adrian.moreno 197121 0 Nov  3 17:04 repoA/
drwxr-xr-x 1 adrian.moreno 197121 0 Nov  3 17:04 repoB/
  1. When you're ready, merge changes from your forked repo back to the parent.

It may be the case that you don't need to ever pursue the 2nd step. You may just get everything done on the forked version and run with that.

  • Related