Method for using git to keep private repositories in sync -


we have development environment spans 2 physical locations.

we in stages of trying merge software development efforts have been, until now, silo'd. lots of duplication etc...

one location drives development while other coming speed. 1 major issue lead development team on archaic servers , doesn't utilize newer github style coding methodologies; looking adopt pull requests , code reviews have advantages how release customers.

here set-up.

location uses gitolite , has "master" repositories

location b uses gitlab because want adopt use of pull-requests , managing users can done through web-interface takes admin burden off of me (we small). among other features like.

what have attempted do, thought simple, set cron job in location b pulls location , pushes location b in night (opposite time zones).

well proven sort of pita. can't seem find way fetch remote branches having not checked them out in manual way before. results in branches never being pushed location b.

am missing obvious? plain stupid trying do? end goal location , b using 1 server running gitlab might take while , convincing of people.

ssh access figured out , working cron job. it's can't finagle git doing want. can fetch --all grabs location b remote well... not want.

here start of script try fetch of remote branches 1 origin has sorts of problems:

remote=locationa ;  brname in `   git branch -r | grep $remote | grep -v master | grep -v head    | awk '{gsub(/[^\/]+\//,"",$1); print $1}' `;    git branch --set-upstream-to $brname $brname;    # or   git branch --track $brname  $brname ;  done 

i'll continue work issue. thought post here make sure wasn't missing obvious or going down ridiculous path.

i able accomplish asking using git-python.

i wrote script iterate through remotes given repository. if remote 'origin' (location a) script fetches branches , tags. script pushes 'secondary' (location b) repo.

i can run script using fcron end updated "mirror" of repository.

again, not sure if sort of crazy problem got myself or if there simpler way of doing it. worked.

script, reference, here isn't 100% complete please use wisely.

""" gitsync.py

the purpose of script automate gitsync between 2 repositories. pull branches , tags 1 remote , push them another.

""" import git git import repo import os   def main():      join = os.path.join     repo = repo(os.getcwd())     git = repo.git     assert not repo.bare      remote in repo.remotes:         print remote         if str(remote) == 'origin':             ref in remote.refs:                 print " " + str(ref)                 try:                     git.checkout(str(ref), '-t')                 except:                     print "could not check-out branch. exists"             git.fetch(str(remote))             git.fetch('-t', str(remote))             git.pull             git.push('secondary', '--all')             git.push('secondary', '--tags')   #------------------------------- if __name__ == "__main__":     main() 

Comments