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
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:
- Add new changes from the original repository. This is quite useful if there is active work and new features are added.
- Offer to infuse your own changes into the original repository .
Fork is done like this:
- Visit the repository of interest page
Click on the fork button:
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:
On your working machine, execute the command (substitute the line from your repository):
git clone git@github.com:username/project.gitOr, 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.gitOr 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/submoduleHere
path/to/submoduleis 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
To begin, add a new remote repository:
git remote add new-origin git@github.com:username/reponame.gitMaking a
pushinto it:git push --all new-origin
If you want to completely get rid of the old repository:
Delete the old repository:
git remote rm originRename new repository:
git remote rename new-origin origin

