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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try now, I just updated the link.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Correct.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
so if it runs on client side then how will it update the submodule on the central repo?
Do I need to use subtrees?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.