How to hide files and folders from Github public

I just want to hide some of my git file from GitHub.

Like this repo .

Is that possible using .gitignore or any other way ?

4

4 Answers

Update: GitHub has allowed for free and unlimited* private repositories for some time. Just mark your repository as private by going to your repository's Settings -> Danger Zone -> Change repository visibility.

* Unlimited in terms of quantity of private repositories. 500 MB storage limit among your private repositories. Public repositories have unlimited storage and do not count against 500 MB.


Using the .gitignore file excludes files from being part of a push to any remotes such as Github, so if you clone the repo on another machine those files won't appear, and if you lose access to your machine the ignored files are gone for good because they are not part of the git version control.

To host your code but hide it from the public, Github offers premium Plans which all you to have private repositories. Marking a repository as private allows you to push and pull your repositories as normal and not have them in public view. Only you and any collaborators have access to the repository.

Students with access to a .edu email address have access to the Github Student Developer Pack which gives you the Developer plan, granting unlimited private repositories and more:

Alternatively, you can use other git repository sites which allow free private repositories such as Gitlab.

0

As of April 2020 Github is now free for teams, that also includes private repositories:

We’re happy to announce we’re making private repositories with unlimited collaborators available to all GitHub accounts. All of the core GitHub features are now free for everyone. 🎉


Okay but how does it answer the question?

Private Repository + md5sum + .gitignore

  • Backup and Share: So in my case I decided to setup another private repository, named exactly as the main one and adding _env at the end of its name. Here I backup all my (not too sensitive) keys and config files related to the main project for free.

  • CI/CD: In my main repository example I added a function that will check if the md5sum of its files are different from the ones in example_dev and if so will automatically overwrite the settings files that have been modified in the main directory.

  • Security: I also made sure to add a .gitignore that will prevents my config files to be pushed publicly.

An actual example. There is a file sfdx-project.json file that keeps track of unlocked package builds

I recently forked a package to open source. Having access to our orgs sfdx-project.json file is not useful for the open source community. So I want to still keep that in our private repo, as all our developers need it. But I never want it to appear in a pull ruest I send to the public repo.

After you have created git add .gitignore, I had a file name .env and put it into the .gitignore. I typed .env. It did not work, so I had to change the file of .env to env. It will not show the env file to the public.

You can learn more hide-files-on-github looking at their .gitignore file

  • extension/node_modules/*
  • !extension/node_modules/github-injection/index.js
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like