Share files between multiple repositories: Advanced Git

Share files between multiple repositories: Advanced Git

Introduction

GitHub is a powerful platform for version control and collaboration, widely used by developers around the world. While it's straightforward to work within a single repository, there are times when you may need to share files between repositories. Fortunately, GitHub offers several methods to achieve this. In this guide, we'll explore one such method: sharing a single file from one repository to another.

Step 1: Firstly, let's clone a repository to our local machine and create a file.

git clone [github_repo](link)

touch xyz.txt

Step 2: Commit and push the changes to the repository on GitHub

git status

git add (file-name)
git commit -m "(message regarding the changes)"

git push origin main

This is an important part to understand, when we use git push command, we declare the destination (the repository we want to make changes to) and the branch of that repository (By default it is set to main)

Step 3: Look for the destinations assigned to the repositories

git remote -v

Step 4: Add another destination linked to another repository

git remote add backup [repository_link](link)

Step 5: Check for the destinations again

git remote -v

Step 6: Now you can push the changes to another repository while being in other

git push backup main

The same changes can now be pushed to second repository from one repository.

Conclusion

Sharing files between multiple repositories is a useful feature that can streamline collaboration and organization. Following the steps outlined in this guide, you can easily share files between repositories and ensure that your projects are well-structured and accessible to your team members.

Did you find this article valuable?

Support Sourav Dhiman by becoming a sponsor. Any amount is appreciated!