1

I have 2 git repositories on github - development-repo and production-repo. All the daily work is committed to development-repo, and whenever I want to put code into production I would like to sync production-repo to get the latest changes, and from there I have automation set up to deploy it to our production environment.

So far I cloned development-repo into production-repo, and that worked fine to get all files. But now I made some changes in development-repo and I would like to push them into production-repo.

I tried running 'git pull https://github.com/[organization]/development-repo.git' from my production-repo, but that gave me a looong list of merge conflicts.

What git command should I use?

Ben Reser
  • 5,695
  • 1
  • 21
  • 29
  • Why do you use different repos for that and not simply 2 branches in 1 repo? That is exactly what branches are intended for and I'm afraid you are making things needlessly complicated by have two different repos. – Robert Rüger Jul 10 '14 at 06:47
  • Because I need to control which developers can actually push code to production - as I understand git, you can't set access rights per branch – user3323387 Jul 11 '14 at 08:53

1 Answers1

0

If you are committed to using two different repositories rather than just a different branch I would recommend setting up two different remote repositories in your local development repository. I'm guessing this is what your current repository layout looks like.

local development repository (LDR)  -->  remote development repository (RDR)

local production repository (LPR)   -->  remote production repository (RPR)

This is probably what you want your repository layout to look like.

local development repository  -->  remote development repository
                             \
                              `->  remote production repository

With the first layout, the development repositories and the production repositories may share the exact same files, but they have completely different commits. This makes trying to sync them a very manual task. Basically you have to copy all the files from LDR to LPR and create a new commit and push that to RPR.

To achieve the second layout, you can issue the git remote add <name_of_remote> <github_address> command within the context of LDR. For example:

git remote add production https://github.com/[organization]/production-repo.git

This would allow you to call git push production master whenever you would like to push the changes you have in LDR to RPR.

Note If you have already pushed from LPR to RPR, you are a little stuck. Since the repositories are completely different, when you try and push from LDR to RPR you will probably get some weird warning messages. Not sure what they will be off the top of my head. You may have to delete RPR on GitHub and recreate it. That or you can use the always very dangerous force push.

Community
  • 1
  • 1
bnorm
  • 908
  • 1
  • 7
  • 14
  • I'm using 2 separate repo's because I need to control which developers can push to production. – user3323387 Jul 11 '14 at 08:56
  • I already pushed from LPR to RPR as you mentioned, but I'll just delete it from Github and recreate it. – user3323387 Jul 11 '14 at 08:57
  • Did this solution work for you? Everything working the way you would like? – bnorm Jul 13 '14 at 16:06
  • Adding the remote repo worked well, but when I push, I get the following error: src refspec master does not match any – user3323387 Jul 16 '14 at 07:53
  • What does 'master' refer to in your push example? The repo name, branch name? – user3323387 Jul 16 '14 at 07:54
  • 'master' refers to the branch name. Did you rename the master branch to something else in LDR? Try [this](http://stackoverflow.com/questions/4181861/src-refspec-master-does-not-match-any-when-pushing-commits-in-git) or [this](http://stackoverflow.com/questions/827351/push-origin-master-error-on-new-repository)? – bnorm Jul 17 '14 at 19:07