How to only make one specific branch of a repository accessible to the public #131435
-
|
Hi all, i want to ask how to only make one specific branch of a repository accessible to the public? We have a repository with many different branches that are all publicly available currently. We only want to publish one of the branches while the rest of the repository remains private. I tried to do that in the Rules setting, but I could not find a way to make the whole repository private. In the rules setting I could only adjust the rights for developers (which is not relevant for me). Does anyone have any idea |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 38 replies
-
|
Hi @PBerit , In GitHub, a repository is either |
Beta Was this translation helpful? Give feedback.
-
|
Hey Idts there's any way to do this directly but you can set it up such that you can create a private repo and then use this
name: Deploy to Public Repo
on:
push:
branches:
- your-branch-name
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
with:
ref: your-branch-name
- name: Push to public repository
run: |
git remote add public-repo https://github.com/yourusername/public-repo.git
git push public-repo your-branch-name:main --force
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
Beta Was this translation helpful? Give feedback.
-
|
Thanks for your comments. @MostlyKIGuess : where and how shall I run the code? I don't really understand what to do with your code? Is it not possible to do this directly in the GitHub Gui? |
Beta Was this translation helpful? Give feedback.
-
|
I managed to go until step 5 (but I don't know if everything was correct). Now I tried several attempts: All yield the same error "fatal: not a git repository (or any of the parent directories): .git" |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for posting in the GitHub Community, @PBerit! We're happy you're here. You are more likely to get a useful response if you are posting your question in the applicable category, the New to GitHub category is solely related to conversations around getting started on using GitHub and the community for beginners of GitHub, Community on Discussions, and those new to different areas of the product alike! This question should be in the Repositories category. I've gone ahead and moved it for you. Good luck! |
Beta Was this translation helpful? Give feedback.
Indeed @PBerit , that tutorial can be a bit tricky, I'm gonna show you the right steps to achieve what you need more easily.
Clone your new GitHub repo (the destination repo) on your system with
HTTPS, then go to the repo folder by runningcd reponame(being "reponame" the actual name of the folder).Now go to your old repo on GitHub, go to the branch you want to add to the new repository and click on
Code=>Download Zip.Drag and drop the contents of the downloaded branch inside your new repo folder (the one cloned in your local system not the remote on GitHub).
Then go to the terminal, (make sure youre inside the new repo folder) and run the following commands in order:
git add .