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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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.  

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

Mikael Sandberg Community Leader Feb 13, 2020

Try now, I just updated the link.

Like mo.entezari likes this

@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 Feb 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: 

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.

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 Feb 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.

Mikael Sandberg Community Leader Feb 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 Feb 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.

Thanks very much!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,776 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you