0

I have a repository (A) where I have been building code, I also have a same older code version in a different repo (B) what is the best way to bring the repo (A) to repo (B). Eventually repo (A) should go away. Basically I want to point towards to B.

Out of these options which one is a good practice:

  1. Edit .git/config file URL - Instead of URL (A) use URL (B) and push all the changes

  2. Do a pull request and bring in the changes (Not sure from repo to repo it can be done (A) is not a branch of (B).

Maybe there are are better ways than above two.

Paul
  • 20,883
  • 7
  • 57
  • 74
add-semi-colons
  • 18,094
  • 55
  • 145
  • 232
  • This question is unclear. How does B have "older code version" than A? Is A a clone of B, and you haven't updated B in a while? Do A and B share some of the same history (i.e. sha IDs)? Or does A have the same files as B, but A's history is completely different than B's (i.e. none of A's sha IDs are shared with B's)? –  Apr 27 '14 at 19:35

2 Answers2

2

You need to git fetch /path/to/other/local_or_not/repo and then merge the changes like you do normally, using:

git merge FETCH_HEAD

Git fetch man page says: "Fetches named heads or tags from one or more other repositories, along with the objects necessary to complete them."

So, overall it should look like this:

cd /path/to/B
git fetch /path/to/A
git merge FETCH_HEAD
# fix merge conflicts and you should be done!

LE: Please note that this approach is equivalent (more or less) to a pull request on github (your second idea), without actually needing github (or whatever git-hosting service you're using).

Paul
  • 20,883
  • 7
  • 57
  • 74
2

There are a bunch of ways, but the most "correct" is just to add a new remote for repo B, and push to it

$ git remote add repo-b http://my-address-for-repo-b

$ git push repo-b master
user229044
  • 232,980
  • 40
  • 330
  • 338
  • 1
    In my oppinion this is far from the correct way, since you'll have to `git pull` in the repo B and since pull is fetch&merge I think a simple fetch&merge DIRECTLY in repo B is the cleanest way, plase see my answer for details on what I mean. – Paul Jul 25 '13 at 14:36
  • 1
    @Paul I think one of us has misunderstood the question. I think he simply has newer commits on repo B that he wants to push to repo B, which is (presumably) an older copy of the same repository. There is no need to fetch/merge here. – user229044 Jul 25 '13 at 14:49
  • @meagar In your answer should repo-b be origin `$git remote add origin http://my-address-for-repo-b` then how should the push command change reflecting that. – add-semi-colons Jul 25 '13 at 15:51
  • Well, a fetch&merge will be done anyway when he will pull in repo B (a pull which he will do if he still works on the code), because that's what a pull is, a fetch and a merge. Pull is porcelain for those two, and your way is just a scrathing with the right hand on the left side of the head. Don't get me wrong, it solves the problem, but in my opinion is a workaround. – Paul Jul 25 '13 at 16:38