DEV Community

Sardar Mudassar Ali Khan
Sardar Mudassar Ali Khan

Posted on

How to remove git from the project and then upload it to the new repo ?

Removing Git from the Project

Step 1: Backup your project
Before proceeding, make sure you have a backup of your project files in case anything goes wrong.

Step 2: Delete the local Git repository

  1. Open your terminal or command prompt.
  2. Navigate to your project directory using the cd command.
  3. Remove the .git folder by running:
   rm -rf .git
Enter fullscreen mode Exit fullscreen mode

This command will delete the hidden .git directory which contains all the version control information.

Uploading to a New Repository

After removing Git, you can now upload your project to a new repository.

Step 1: Initialize a new Git repository

  1. Create a new empty repository on your preferred Git hosting service (GitHub, GitLab, Bitbucket, etc.).
  2. In your terminal, navigate to your project directory.
  3. Initialize a new Git repository:
   git init
Enter fullscreen mode Exit fullscreen mode

Step 2: Add your files and commit

  1. Add all your project files to the new repository:
   git add .
Enter fullscreen mode Exit fullscreen mode
  1. Commit the files:
   git commit -m "Initial commit"
Enter fullscreen mode Exit fullscreen mode

Step 3: Link the local repository to the remote one

  1. Link your local repository to the new remote repository:
   git remote add origin <new_repository_URL>
Enter fullscreen mode Exit fullscreen mode

Replace <new_repository_URL> with the URL of your new repository.

  1. Push your code to the new remote repository:
   git push -u origin master
Enter fullscreen mode Exit fullscreen mode

This will push your code to the new repository's master branch. If you have a different branch name, replace master with your branch name.

Remember to substitute <new_repository_URL> with the actual URL of your new repository.

These steps will create a new Git repository for your project and upload the files to the remote repository.

Top comments (7)

Collapse
 
cawal profile image
CaWaL

Is this a joke? You will lose all the versioning history doing it. Usually, all you need is to change the URL of the remote and push things to the new repo.

Collapse
 
sardarmudassaralikhan profile image
Sardar Mudassar Ali Khan

Try it by your self man then put your thoughts here other wise i don't consider this type of shitty comments on my posts

Collapse
 
cawal profile image
CaWaL

Sorry, but this post is dangerous for the begginer. Doing as it is said, you will lose all the versioning information in the new repository and this should be noted at the preamble.

Usually, someone wants to move all the repository and all of its history to a new place. This should be done changing the URL of the remote (I think it's made using 'git remote --set-url ...') and pushing the repo to the new URL.

Thread Thread
 
cawal profile image
CaWaL

Here what I'm talking about: stackoverflow.com/a/1484666

Thread Thread
 
cawal profile image
CaWaL

But you are right: I shouldn't called the post a joke. I'm sorry for it.

Thread Thread
 
sardarmudassaralikhan profile image
Sardar Mudassar Ali Khan

Wiseman Thanks for Understanding my point.

Collapse
 
rahul221389 profile image
Rahul charan

clearly explained.