Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Merging multiple repos to a central one when there is a commit on one repo

mo.entezari February 13, 2020

So I have multiple repositories and a central repository.

Whenever there is a commit on any of the "multiple repositories" I need that commit to go to the central repository.

Can this be achieved?

1 answer

1 accepted

0 votes
Answer accepted
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 13, 2020

Hi @mo.entezari,

Welcome to the Atlassian Community.

You could do this with Git Submodules, or Git Subtrees. See this blog post for more information about both options, Git Submodules vs Git Subtrees.  

mo.entezari February 13, 2020

Thanks @Mikael Sandberg but the link does not take me anywhere.

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 13, 2020

Try now, I just updated the link.

Like mo.entezari likes this
mo.entezari February 13, 2020

@Mikael Sandberg I'm not sure if this solves my problem. If I use sobmodules, in order to get any changes in the submodules I have to update the central repo.

I want any changes to submodules to automatically commit to the central repo without me having to update. The whole purpose is that when submodule repo has a commit that commit comes to central one and that commit will trigger my pipeline from the central repo

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 13, 2020

You can use Git hooks to automate the update of your central repository. The only downside is that you have to install the hook on each client. Have a look at these two blog post on how to distribute hooks:

https://www.darrenlester.com/blog/including-hooks-in-a-git-repository 

https://www.viget.com/articles/two-ways-to-share-git-hooks-with-your-team/ 

Git will not allow you to push a repository to another repository unless the stem from the same "master" repository. That would cause an out-of-sync in Git's internal storage. So you only option is to use either submodules or subtrees.

mo.entezari February 13, 2020

When we update for submodules can we make it so that a branch is created with the update on it? Instead of updating on master?

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 13, 2020

Yes, you just have to configure your hook to do that. Git hooks are just scripts that execute whatever you want them to do. Have a look at Git hooks for some examples of what you can do.

mo.entezari February 13, 2020

Thank you

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 13, 2020

Correct.

mo.entezari February 13, 2020

so if it runs on client side then how will it update the submodule on the central repo?

Do I need to use subtrees?

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 13, 2020

If you use submodules all changes are done in that submodule repository and once done you cd up to the parent repository and update the submodule pointer. The second part you should be able to automate with a hook.

If you use subtrees the process is a bit different. There you should be able to run the hook in Bitbucket so that you do not have to distribute your hook out to every client. If you go with subtree, then all changes should be done in each subtree repository, just like submodules, and then in the post receive hook on Bitbucket your hook would go into the central repository and run a git subtree pull.

I have only used git subtrees, because we decided to have a copy of the child repository in the central repository would be the simplest way of working. I would recommend reading the blog post I linked to above, it has detailed instructions on how to use git submodules. I would also check out this tutorial, Git subtree, and then decide what works best for your environment.

mo.entezari February 13, 2020

Thanks very much!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events