Reputation: 7153
I've seen similar questions about this, but none that give me confidence to risk mangling my git. I'm not a total noobie, but have never had the need to deal with two repos so I want to know the right way to do this.
I'm working on a project where we have one repo for staging (SRV-S
) and another repo for production (SRV-P
). Both have "production" branches that go live if pushed to, via Jenkins magic.
I'm not a git wiz so I maintain separate project folders for each repo. I make changes on SRV-S
(staging repo, production branch) and once approved, manually copy those files over to my SRV-P
folder (production repo, production branch). Then I cd into SRVF-P
and git add, commit, push. Tedious.
Is there an easy way I can have be in the staging repo, on the branch named 'production', then pull a branch named 'production' from another repo, then push to either repo. i.e. that 'production' branch would exist in two repos with the same history.
Upvotes: 0
Views: 77
Reputation: 3001
The core issue is that you have a bad versioning strategy. You should not be maintaining two repos.
Merge the repos into one and maintain a separate branch for production and staging. Then merge between the two branches.
Upvotes: 1
Reputation: 30204
I think your major problem is that the repos are not really tied, are they? Like, you have two separate repos, two branches with the same name... but they have always run in parallel, no common ancestor. If that's the case, you can still play with a single local repo where you will work and you have two remotes set up on it (srv-p, srv-s). Now.... I guess you will be mostly doing work against srv-s... and then at some point you decide that what you have in srv-s/production is what you would like to have on srv-p/production (content-wise, not history-wise).
The way to do that with the least effort and without having to move stuff around by hand is:
git checkout srv-s/production
# you would be on detached HEAD
# next step is where the magic happens:
# - move branch "pointer" to srv-p/production
# - keep our content as is, all differences between our working tree
# and srv-p/production will be on index, ready to be committed
git reset --soft srv-p/production
# now we create a new revision so that the two branches have
# exactly the same content
git commit -m "A new version in srv-p/production"
# now we push into srv-p/production cause right now we are still
# on detached HEAD
# we actually haven't moved any branch either locally
# or on any of the two remotes
git push srv-p HEAD:production # send current HEAD to srv-p/production
I am doing this without any local branches, you could get the flow going with local branches as well.
Upvotes: 1