0

Git offers nice option to track changes in multiple remote branhces. But is there a way to set this feature by default? What I mean is that when someone clones a repository, it's is by default already tracking two remotes.

The scenario is like this

  • We have a some shared code in remote repo called libs
  • We have another project that has forked this repo in order to enhance it, called enhancedLibs
  • When someone makes a commit to libs, a manual sync is done to add the changes to enhancedLibs as well.
  • Changes from libs are taken to enhancedLibs, but not the other way around (or it is very rare)

There are some obvious problems with this

  1. The sync is forgotten to do (with a dynamic language there errors are spotted quite late)
  2. Git does not directly show in the commit history that where the change came from. It's up to the developer to add details.

Tracking multiple branches seems to fit the bill per my understanding, but the setup is the question here. we are using Atlassian Stash, but I'd prefer a Git only solution if available.

Also keen to know of alternative solutions. For example, would some mirror setup help here?

Community
  • 1
  • 1
kaskelotti
  • 4,709
  • 9
  • 45
  • 72
  • The initial remotes are set exclusively based on the source from which someone is cloning a repository. There is no way to automatically insert additional remotes, but you could ship a setup script that someone could run to configure their local repository. – larsks Aug 25 '15 at 19:25
  • @larsks a setup script is an excellent option for a alternative solution mentioned in the post. I think you should add it as answer. And you are also answering the question: Initial multiple remote setup is not possible. Is this with Git-only tools, or can you confirm for Atlassian Stash tools also? – kaskelotti Aug 25 '15 at 19:42

2 Answers2

2

Posting as an answer as requested:

The initial remotes are set exclusively based on the source from which someone is cloning a repository. There is no way to automatically insert additional remotes, but you could ship a setup script that someone could run to configure their local repository.

This is a fairly common solution, since many projects want contributors to run a standard set of pre- or post-commit hooks, for example.

I'm not at all familiar with Stash, but if folks are using generic git clients locally it doesn't particularly matter what service you're using to host the repositories. If Stash includes proprietary clients as well, that is a question best directed to Atlassian.

larsks
  • 277,717
  • 41
  • 399
  • 399
1

The solution you're asking for doesn't really involve Stash (disclosure: I'm a product manager). I did do some investigation into a "post-clone" hook of sorts to set up something like what you're asking for though. In short, it's possible, but not pretty, using a post-checkout hook. That requires a change to each user's global git hooks, so it only really moves the problem.

All that said, I think using multiple remotes is the wrong solution. If you want one repo to be derived from another, it would be better to do that centrally instead of depending on client side configuration. The simplest approach would be to make enhancedLibs a fork of libs. They can be synchronized on the server as needed. Users should pull and push to one or the other depending on where the change belongs, ideally working from 2 local clones to avoid confusion. If some users shouldn't be contributing to either repository you can use branch permissions in Stash to enforce that.

Community
  • 1
  • 1
Rog
  • 4,075
  • 2
  • 24
  • 35
  • Stash's fork syncing looks quite good. Unfortunately, it seems to sync the branches and tags as well, which is not what I need/want. – kaskelotti Aug 27 '15 at 05:59
  • Why wouldn't you want the branches/tags in sync? I'm open to raising a new feature request if there's a common use case – Rog Aug 28 '15 at 06:56
  • The libs have their own lifecycle and versioning scheme already. Syncing the tags/branches would only complicate things. It might be that the enhancedLib will be the only one in the future and the this setup is no longer needed, but is not going to happen in short time (not in this year at least). – kaskelotti Aug 28 '15 at 08:51