Akaanksh Raj
Akaanksh Raj

Reputation: 126

Auto pushing to a specific folder on GitHub or other Git service

The Situation: I have one Git Repo with files; let's call it "Robot". When I commit to Robot, I want something to auto-commit my new commit to another big repo under a specific folder.

The Problem: I don't know how to do it. I know GitLab has mirror repository, but it mirrors the whole repo and it won't do it to a specific folder.

EDIT:

Here's an analogy: The big repo is like a CDN and Robot is a framework.

Upvotes: 2

Views: 331

Answers (1)

umläute
umläute

Reputation: 31274

Basically there are two ways to mirror a repository to multiple locations:

  • client side (push to two repositories at once)

  • server side (only push to a single serverA, and let the server forward the push to another serverB)

client side

If you are mainly working from a single working copy (that is: you only clone the respository to a single machine; and do all the work there), and bandwidth is not an issue (and since git mostly deals with sourcecode that should be true in most circumstances), the simplest way is to just add two (2) remotes to your working copy (or copies):

 git clone uri://serverA/myrepo.git
 cd myrepo
 git remote set-url --add --push origin uri://serverB/robot.git
 git push

The only drawback here is, that whenever you clone anew, you have to setup the additional push-url.

See also Git - Pushing code to two remotes

server side

You can also deploy a server-side post-receive hook, that will just calls git push to another server.

  1. create the repository on serverB: uri://serverB/robot.git

  2. create a bare repository on the serverA

    git create --bare myrepo.git
    
  3. add a remote to the bare repository

    git remote add origin uri://serverB/robot.git
    
  4. add a post-receive hook to the bare repository on serverA

    $ cat > myrepo.git/hooks/post-receive << EOF
    git push --all
    git push --tags
    EOF
    
  5. on your desktop, clone uri://serverA/myrepo.git, add files and push them.

    the files get automatically forwarded, provided that the user which runs the git-hook on the server is actually allowed to push to serverB.

I find this favourable if multiple working copies and multiple users are involved. There are two issues though:

  1. you need to be able to create post-receive hooks on the server. This usually means that you must have administrative access to the server (e.g. be able to ssh into it; or have other super-cow powers). This rules out github as your serverA.

  2. in virtually all cases you must authenticate to the serverB. E.g. you can use password-less ssh-keys (stored on the server) for this. (github allows you to add Deploy Keys with write-access to each repository).

See also Git push to one remote repo which deploys to multiple other remote repositories

Upvotes: 1

Related Questions