On Mon, 21 Jul 2014 06:34:08 -0700 (PDT)
Mirko Gogic <gogicmi...@gmail.com> wrote:
> I have a following problem for a long time we had two separate
> projects on two separate git origins.
> server A and server B
> Now code is getting very similar, and am trying to push updates
> Me and few of my friends are working and pushing to server A, then i
> need to merge changes from server A to to local copy of server B and
> then i will push to server B ( one person is doing this ).
> I would like to be able to merge from server a to my local copy of
> server b. Currently am using third party tool to merge this but as we
> are using git on both i was wondering can git help me.
> Can i somehow do this easier with git ?
I'm not sure I completely follow but answering anyway...
A bit of background information first. There are two ways to refer to
a remote repositories in Git:
1) You might use an URL of that repository directly;
2) You can make a local repository permanently "know" about any number
of remote repositories. These things are called "remotes" and are
operated on using the `git remote` command.
The `git clone` command impliticly creates one remote for you: it's
named "origin" and has its URL set to that specified when cloning.
The name "origin" is in no way special: it's just the default -- in the
same way "master" is the default name for the first branch to be
created when a repository is initialized.
It seems that for your case -- reconciling changes between two
repositories using the third (local) repository -- using remotes is the
Let's now use this knowledge to actually set things up.
First, you need to clone the repository B.
Then, configure the resulting local repository so that it "knows" about
the repository A:
git remote add repoa REPO_A_URL
This command will add the remote named "repoa" with the URL REPO_A_URL
to your local repository. No A's data is fetched at this point.
Next, you will need to bring the "interesting" objects from A into your
local repository. Say, you want to merge branch "feature" form A into
the branch "master" of B. You do it like this:
1) Make sure you have the recent version of B's history:
git fetch origin
2) Make sure your local branch "master" is the same as that branch in
the repository B:
git checkout master
git merge -ff-only origin/master
3) Fetch the branch "feature" from the repository A:
git fetch repoa feature
This comand will create the so-called "remote branch" named
"repoa/feature" in your local repository.
If you want all the branches of A, you can do
git fetch repoa
git remote update repoa
4) Now you can merge "repoa/feature" into "master":
git merge repoa/feature
Resolve conflicts, if raised, commit and then try to
update the "master" branch in the repository B:
git push origin master
That's basically all that is needed: to merge between branches in
different repositories, bring the relevant objects of all those
repositories into your local one, then merge.
One more thing. You told us that the code bases in A and B are quite
similar. You then might consider making them into the single code base.
You received this message because you are subscribed to the Google Groups "Git
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email
For more options, visit https://groups.google.com/d/optout.