I have the following task: GitHub has a repository. I create a project and pump it out. After that, I need to get rid of this repository and create a new one, upload it to GitHub, and so that it already tracks the changes, and commit to it. How to do it right?

    2 answers 2

    The easiest and most convenient way is to make your own fork of the original repository and clone it. Moreover, this method is correct from the point of view of github-flow, the methodology for organizing collaboration with git / github. Even if you don't need it yet, it may come in handy later.

    With this option you will have a handy tool to:

    1. Add new changes from the original repository. This is quite useful if there is active work and new features are added.
    2. Offer to infuse your own changes into the original repository .

    Fork is done like this:

    1. Visit the repository of interest page
    2. Click on the fork button:

      enter image description here

    3. After a short wait on your page in GitHub, a copy of the repository appears - fork. There is a text field from which you can copy the address for cloning:

      enter image description here

    4. On your working machine, execute the command (substitute the line from your repository):

      git clone git@github.com:username/project.git 

      Or, if you first cloned someone else's repository, you need to reconfigure your repository to your own.

       git remote set-url origin git@github.com:username/project.git 

      Or so, if you want to connect the repository as a submodule to an existing and versioned project (suitable for different dependencies and components of your project):

       git submodule add git@github.com:username/project.git path/to/submodule 

      Here path/to/submodule is the path to the directory in which the contents of the repository connected as a submodule will be located.

    You now have a local repository copy. It is already configured to pull / push to your copy on GitHub.

    A couple of moments:

    so that he is already tracking changes

    Changes are always monitored by your local repository. Files deleted in a way that they are on your hard drive are never transferred to a remote one on GitHub and it cannot know about the changes you made locally, but did not launch.

    and make comments on it

    Do not confuse, it is called "commits", "commit". Here you can read about it and find a couple of good links: https://ru.stackoverflow.com/tags/git-commit/info

      1. To begin, add a new remote repository:

         git remote add new-origin git@github.com:username/reponame.git 
      2. Making a push into it:

         git push --all new-origin 

      If you want to completely get rid of the old repository:

      1. Delete the old repository:

         git remote rm origin 
      2. Rename new repository:

         git remote rename new-origin origin