views:

89

answers:

3

Hi, I have a remote read-only git repository A, which I have cloned in my local filesystem. A is updated periodically, and I pull and merge the updated code in my system after each update.

I want to collaborate with my team members on the files of A, for which, I have create a new remote repository B.

How do I manage to sync B with my local repository? I would like to learn the proper command sequence and configuration options to achieve my goals. Here are the scenarios I would like to be able to solve: 1. Pull from A after there are updates, push it to B. 2. Pull from A, merge it with my local files, then push it to B, merging with the repo on B. 3. I would like all of A, my local repo and B to have identical branches.

I would be thankful for any help. If my question is not very clear, please mention it, and I will try to edit it. Thanks.

A: 

I'd suggest setting up cronjob on a host which has B. This way updates from repo A are being pulled in a timely manner (say twice an hour). And you just need to pull from B.

Eimantas
The read-only repo on A contains updates and my team has to work on that repo. For that, right now, all of us have cloned A in our local machines and we pull every time a new update arrives. We work on our local files and exchange files with each other.But I want our team to have a private repo B on which we can push our updates (so that the rest of us can keep in sync).I don't have ssh access to B (or privilege to create cron jobs). I want to learn the proper method to do the task- after that I will decide on a proper automation mechanism myself.
jjossarin
+1  A: 

you can try

git clone repoB url...
git remote add repoA url-to-repo-A
git pull repoA

1)

git pull repoA
git push repoB

2)

git pull repoA
git checkout local-branch-to-merge
git merge repoA/remote-branch-to-merge
git push repoB

3) I don't sure if there is any trick to checkout all the branches on repoA to repoB or to local repo with just one command... if there is none, you can always do it manually with

git checkout --track -b branch1 repoA/branch1

and when you push, they should push to the corresponding branch in remote

insidepower
Thanks @insidepower for the help. Can we pull from one remote repo and push into another remote repo? Do I need to change some config settings (like URL of the remote repo1 and remote repo2)?
jjossarin
@jjossarin: yup, you just need to do "git remote add <remote-ref> <server-url>" then git push <remote-ref> <local-branch>:<remote-branch>...
insidepower
+1  A: 

Hi,

I'm assuming that you have two remotes named A and B that have just the url configured. If you don't follow the refspecs, read the relevant chapter in the ProGit book.

1: Pull from A after there are updates, push it to B

$ # pull = fetch + (often fast-forward merge)
$ git fetch A # fetches all objects from A (all branches, commits; everything)
$ git push B 'refs/remotes/A/*:refs/heads/*'
$ # I've quoted so that the shell doesn't try to expand the *

EDIT: I've assumed that you do not want to merge changes into your local branches.

2: Pull from A, merge it with my local files, then push it to B, merging with the repo on B.

$ git pull A # fetch + attempt to merge changes in all branches
$ # Resolve any conflicts here
$ git push B '+refs/heads/*:refs/heads/*' # omit the + if it's a FF push
$ # Default is to push matching branches

EDIT: The above doesn't merge the changes in B. If you'd like to do that, you must pull changes from B also and merge them into your local branches before pushing.

3: I would like all of A, my local repo and B to have identical branches

$ git pull A
$ git checkout branchx
$ git reset --hard A/branchx # Warning! All local changes will be destroyed
$ # Repeat the above for all branches
$ git push B '+refs/heads/*:refs/heads/*' # Warning! Data in B is overwritten

EDIT: If you'd like to remove stale tracking branches, run

$ git remote prune A
$ git remote prune B
Ramkumar Ramachandra