Hiding files using Git

Sankaran Namboodiri
2 min readDec 9, 2018

--

We have all had situations where we need to hide some files. We have used all kind of tricks to do it.

  1. The most obvious one to set the ‘hidden’ property to true or adding a ‘.’ in the beginning of the file name.
  2. Some go the extra step of changing the icon to transparent and making the filename blank.

We have all gone a long way from that. We have learned a lot more tools (well for other useful things, obviously). Maybe we can do better.

We will be using Git for this purpose. We use the branching feature in git to hide our files. We create a new branch, commit our files in the branch and then checkout to the master branch. This makes our files hidden in the folder unless we checkout our hidden files branch.

What is Git

Git is a version control tool. It used for keeping track of the changes you make in a project and also to collaborate with a team. It was obviously not designed for what we are about to use it for.

Installing Git.

Check out these steps to setup Git on your computer.

Hiding your files/folders

  1. Open Command Prompt / Terminal. Change directory into the folder which contains the file/folder you need to hide.
cd <path_to_directory>

2. Initialize git.

git init

3. Add a readme file. This file does not serve any particular purpose. Since we need to make an initial commit, there have to be some files committed in the initial commit, and we don’t want that to be the files that we are going to hide.

Linux / OS X

touch readme.txt

Windows

echo.>your_file.txt

4. Commit the readme file as the initial commit in the master branch

git add readme.txt
git commit -m "Initial commit"

5. Create a new branch, to commit our secret files. Choose any branch name you like.

git checkout -b hidden

6. Copy all the files into the directory. And create a new commit in the hidden branch

git add .
git commit -m "avada kedavra"

7. Now checkout the master branch

git checkout master

Ta-Da!
Now all the files are hidden from the folder.

Of course, this method has its flaws. A person with fair enough knowledge in git can find the file if he knows its a git repository, but the security lies in people not checking if each and every folder if it is a git repo or not.

--

--