Reputation: 3515
My task is to clone a repository on GitHub to multiple repositories locally.
All the repositories should have the same codebase as the old repository that was cloned. Then I will be able to make code changes to each repository and push each of them to an individual repository on GitHub.
I was able to clone the old repository to multiple repositories pushed onto GitHub as above. But how can update each of the cloned repositories with the changes made to the old one?
Upvotes: 1
Views: 180
Reputation: 3515
Thanks to driusan's answer, I think my answer to the question is: Clone the upstream repo: OLD_REPO_URL to new repositories on my own account on GitHub:
https://github.com/{MY_ACCOUNT}/parse-server-example-APP1
https://github.com/{MY_ACCOUNT}/parse-server-example-APP2
https://github.com/{MY_ACCOUNT}/parse-server-example-APP3
by the following commands:
git clone https://github.com/ParsePlatform/parse-server-example parse-server-example-APP1
cd parse-server-example-APP1
git remote rm origin
git remote add origin https://github.com/{MY_ACCOUNT}/parse-server-example-APP1
(repeat for 2 and 3)
Now that new repositories have been created, I can work each of them and make changes to the code. Push code changes back to origin when it's done.
If the OLD_REPO has been updated, run the following commands to fetch and merge updates with the cloned repos:
cd parse-server-example-APP1
git remote add upstream https://github.com/ParsePlatform/parse-server-example
git fetch upstream
git merge upstream/master
git push
Upvotes: 0
Reputation: 550
Your question is a little confusing. As the comments say, it sounds like you want branches, not repositories, if this is all for yourself. If there is some reason you're trying to fork your code and they need to be different repositories, the default remote for any push/pull operation is origin
. By default, origin
points to the remote that it was cloned from, but there's nothing special about it and it can be changed with the git remote
command.
For instance:
git clone https://github.com/ParsePlatform/parse-server-example parse-server-example1
cd parse-server-example1
git remote rm origin
git remote add origin https://github.com/ParsePlatform/parse-server-example1
(repeat for 2 and 3)
Would achieve what you're asking. If there's already different forks, you can make remotes with other names and be explicit in "git push" about what remote/branch you want to push to.
For instance:
cd parse-server-example1
git remote add example2 https://github.com/ParsePlatform/parse-server-example2
git push example2 master
(repeat for as many different repos/names as you want, ie.)
git remote add example1 https://github.com/ParsePlatform/parse-server-example1
would push your (local) example1 code to the example2 fork and (after the above)
git fetch example2
git checkout example2/master
(do stuff, maybe commit)
git checkout example1/master
would switch between the different forks locally. This is generally a better way to work, unless there's a reason you need multiple copies cloned into different directories at the same time.
Upvotes: 1