1

I have a microservices application, so the front-end on the first repo and two different backend APIs on two different repos. I want to add all these to someone else's empty repo and I am not sure how to do this.

I tried doing a git remote add of the other persons repo and I get this:

danales-MacBook-Pro:freelance-camp-fe danale$ git remote add https://github.com/Meridian-Business-Centers/Interview-Sample-App.git
usage: git remote add [<options>] <name> <url>

    -f, --fetch           fetch the remote branches
    --tags                import all tags and associated objects when fetching
                          or do not fetch any tag at all (--no-tags)
    -t, --track <branch>  branch(es) to track
    -m, --master <branch>
                          master branch
    --mirror[=<push|fetch>]
                          set up remote as a mirror to push to or fetch from

When I do a git remote add microservice master I get this error:

danales-MacBook-Pro:freelance-camp-fe danale$ git push microservice master
remote: Permission to Meridian-Business-Centers/Interview-Sample-App.git denied to ldco2016.
fatal: unable to access 'https://github.com/Meridian-Business-Centers/Interview-Sample-App.git/': The requested URL returned error: 403

I tried pushing it to my own forked version and got this error:

danales-MacBook-Pro:freelance-camp-fe danale$ git remote add microservice https://github.com/ldco2016/Interview-Sample-App.git
fatal: remote microservice already exists.
danales-MacBook-Pro:freelance-camp-fe danale$ git push microservice master
To https://github.com/ldco2016/Interview-Sample-App.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/ldco2016/Interview-Sample-App.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
danales-MacBook-Pro:freelance-camp-fe danale$ git push -u microservice master
To https://github.com/ldco2016/Interview-Sample-App.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/ldco2016/Interview-Sample-App.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Daniel
  • 14,004
  • 16
  • 96
  • 156

1 Answers1

1

Go into every separate repo and add a remote (say, personal) with the url of other persons empty github repo. Now push the code like git push personal master.

Say, you have repo1, repo2 and repo3. And a personal repo perRepo (want to add repo1, repo2 and repo3 codes here).

# Go into repo1
$ git checkout master    
$ git remote add personal <perRepo-url>
$ git push personal master

# Go into repo2
$ git checkout master    
$ git remote add personal <perRepo-url>
$ git push personal master

# Go into repo3
$ git checkout master    
$ git remote add personal <perRepo-url>
$ git push personal master

Add Submodule: General command: git submodule add <git@XXX:YYY> <externals>.

  • git submodule add: Simply tells Git we are adding a submodule
  • git@XXX:YYY: External repository URL that is to be added as a submodule
  • externals: This is the path where the submodule repository will be added to the main repository.

More Submodule

Add repo1, repo2 and repo3 as submodule of perRepo.

# Go into perRepo
$ git submodule add <repo1-url> <path>
$ git submodule add <repo2-url> <path>
$ git submodule add <repo3-url> <path>

$ git submodule update --init --recursive

N.B. when repo1/repo2/repo3 would be updated you need to run git submodule update command to get the updated changes into perRepo repo.

Sajib Khan
  • 22,878
  • 9
  • 63
  • 73
  • Sajib, so perRepo is the other persons empty github repo, correct? I am trying to add repo1, repo2 and repo3 to that one perRepo. Do I have this correct? – Daniel Feb 06 '17 at 03:00
  • I tried that Sajib and look at the error I got above. – Daniel Feb 06 '17 at 03:06
  • You need to give remote name say, personal, git remote add `personal`. General command `git remote add ` – Sajib Khan Feb 06 '17 at 03:07
  • When I do that it says permission denied, I documented the error above. – Daniel Feb 06 '17 at 03:10
  • Yes, `error: 403` (permission denied). Make sure you have write permission to `Meridian-Business-Centers/Interview-Sample-App` repo. – Sajib Khan Feb 06 '17 at 03:13
  • I am making little headway here. I tried pushing it as you outlined to a forked repo and got the error above. – Daniel Feb 06 '17 at 03:23
  • Yes. I think you don't have write permission, then you can create pull request `from your-repo to others-repo`. Or, ask the others-repo author to give write-permission. – Sajib Khan Feb 06 '17 at 03:32
  • I got this working, but its not what I wanted. It adds everything together. How can the other person distinguish between each separate project? I couldn't tell the difference. – Daniel Feb 06 '17 at 03:52
  • Here, the projects seems like a single project (It's normal). You can see `commit message/author` by `git log` command to distinguish. Other ways you can use Git Submodule concept keeping the repos as a subdirectory into other's repo. See http://stackoverflow.com/q/12078365/4133798 – Sajib Khan Feb 06 '17 at 04:10
  • I think the git submodule is the answer, but I have no idea how to implement. If you want, go ahead and post that as the answer. – Daniel Feb 06 '17 at 04:49
  • I have added `git submodule` part. – Sajib Khan Feb 06 '17 at 05:13
  • Sajib, thank you for this, but what about repo3, what happens to that? – Daniel Feb 06 '17 at 05:28
  • oh, Similar as repo1/repo2 (I missed it). Edited my answer. – Sajib Khan Feb 06 '17 at 05:30