DEV Community

jcarloscandela
jcarloscandela

Posted on

Managing Public and Private Repositories in a Project

Projects often require a combination of public and private repositories to manage code effectively. This strategy is particularly useful for maintaining an open-source version while safeguarding proprietary or sensitive information. Below, we'll walk through the process using GitHub, but the principles apply to any Git hosting service like Bitbucket or GitLab.

Forking a Public Repository

To start, we'll fork a public repository into our account. Let's use GitHub for this example, but the process is similar elsewhere. Suppose we're forking a blog template built with Astro:

Step 1: Fork the public repository to your account. For instance:

Blog Template

Step 2: Clone the forked repository to your local machine. Adjust the URL with your username:

git clone https://github.com/yourusername/blog-template
Enter fullscreen mode Exit fullscreen mode

Creating a Private Repository

Next, we need a private repository for internal development. Let's call it personal-blog-template. This repository will house content not intended for public viewing, such as personal blog posts.

Adding the Private Repository as a Remote

To interact with the private repository, we'll add it as a remote:

git remote add private https://github.com/yourusername/personal-blog-template
Enter fullscreen mode Exit fullscreen mode

Verify the addition:

git remote -v
Enter fullscreen mode Exit fullscreen mode

Making Changes and Pushing to the Private Repository

Now, let's upload changes to the private repository. Create a new branch to prevent conflicts:

git checkout -b release
Enter fullscreen mode Exit fullscreen mode

Make desired changes and commit them:

git add .
git commit -m "Add some changes to the README.md file"
Enter fullscreen mode Exit fullscreen mode

Push changes to the private repository:

git push private release
Enter fullscreen mode Exit fullscreen mode

Integrating Changes into the Public Repository

Suppose we want to merge changes from the private repository into the public one.

Fetch changes from the private repository:

git fetch private
Enter fullscreen mode Exit fullscreen mode

Merge the changes into the public repository:

git merge private/release
Enter fullscreen mode Exit fullscreen mode

Conclusion

Managing both public and private repositories within a project is essential for maintaining transparency while protecting sensitive information. Whether for open-source projects or internal development, this approach ensures flexibility and security. By following these steps, you can effectively collaborate and manage your project across multiple repositories.

For enhanced control, tools like Husky can prevent accidental uploads of sensitive branches to public repositories. Experiment with these techniques to streamline your workflow and safeguard your project's integrity. Thank you for reading!

Top comments (0)