Kevin
Kevin

Reputation: 13226

Git - multiple repositories?

Is it possible in Git to do the following, easily?

When local development occurs, I want the push to push changes into GitHub, and push those same changes to the other repositories simultaneously.

I tried doing this with --mirror, but with a team of 7 working on the same project, it seems prone to removing feature branches when the mirror is updated.

Thoughts? Is there any way to do this without manually editing the .gitconfig file to manually define an origin that points to multiple repo URLs? Could this be done with a hook?

Upvotes: 2

Views: 555

Answers (2)

user456814
user456814

Reputation:

You can simply define an alias to do this:

git config alias.pusheverywhere \
"!git push github && git push bitbucket && git push production"

The && in the command is logical AND, so the command on the right side of it will only execute if the command on the left side succeeds without errors.

Upvotes: 4

VonC
VonC

Reputation: 1329092

Mirroring a got repo can be tricky, especially if you don't have created your downstream repo with git clone --mirror.
And in your case, you wouldn't create your local ("downstream") repo that way, since you have three upstream mirror repos you want to maintain.

The blog article "How to properly mirror a git repository" mention that, for a local repo to mirror push, you need to:

git fetch --prune upstream_repo

(to be sure to clean remote tracking branches that are tracking deleted branches of the upstream repo)

git push --prune upstream_repo +refs/remotes/origin/*:refs/heads/* +refs/tags/*:refs/tags/*

(and that doesn't include git notes, by the way)

Pushing to three repos is one way, but I would prefer:

  • pushing the to prod repo
  • having a post receive hook which pushed to GitHub and BitBucket repos

If a problem is detected at the prod repo (like a missing comment on a commit, or some other policy not respected), you get a chance to:

  • deny the push on prod
  • not pollute the GitHub and BitBucket repos

Upvotes: 3

Related Questions