I recently working in a project and I want to make two repositories with same code. So I duplicate one and tried to insert into git as a new repository. But it directed to the old repositories and committed there. Any help from someone please.
Asked
Active
Viewed 1,045 times
1
-
When you duplicate it, did you remember to exclude the git folder? – Martheen Jun 14 '20 at 01:30
-
@Martheen should I want to delete git folder before making new repository? I do not know about that – Kamalka Fernando Jun 14 '20 at 01:36
-
1If you don''t want to keep any git commit history, delete it on the new repo folder. If you want to keep them but commit to different repo, try https://stackoverflow.com/questions/5181845/git-push-existing-repo-to-a-new-and-different-remote-repo-server – Martheen Jun 14 '20 at 01:48
-
@Martheen That means, imagine I have **project1** folder and I made a git repo and added it. Then I want the same code slightly change for another project, So I create **project2** folder and insert **project1** folder itself to it. So I want to push **project2** folder as a new repo to git. So all I want to delete the .git folder in /project2/project1 , right? and again start with **git init**. Is this what you mean? – Kamalka Fernando Jun 14 '20 at 02:57
-
Yes, assuming you really don't care about maintaining commits between those two repos. Otherwise @JustinBeckwith answer is a better option. – Martheen Jun 14 '20 at 03:10
-
@Martheen ok. Thank you for answering! – Kamalka Fernando Jun 14 '20 at 03:44
1 Answers
3
If you are working in a single directory on your machine, and want to push code to multiple GitHub repositories, that's totally possible. What you're looking for is multiple remotes.
When you did a git clone
, it probably created a origin
remote that looks like git@github.com:JustinBeckwith/linkinator.git
.
To see the remotes you already have, try:
$ git remote -v
To add a second remote, first find the URI on the second GitHub repository you want to use:
Copy that URI, and add it to your existing repository with:
$ git remote add second git@github.com:JustinBeckwith/linkinator-2.git
You could then push code by saying:
$ git push second master
Hope this helps!

Justin Beckwith
- 7,686
- 1
- 33
- 55
-
**git push second master** means is this creating another branch in existing repository? – Kamalka Fernando Jun 14 '20 at 03:00
-
-
@JustinBeckwith **git remote add second git@link-of-new-repository** ,Is it? I am asking every single thing as I messed up my project while making new repository and I am afraid of typing git code. So please be patient to answer my questions.Thank you! – Kamalka Fernando Jun 14 '20 at 03:50
-
isn't the default branch of all newly created repos "main" and not "master"? using master gave error. **git push second main** should do the trick in case some gets the following error. `error: failed to push some refs to 'https://github.com/someone/something.git'` – Calladrus2k1 Mar 12 '22 at 05:16