0

Basically, I don't want my firebase credentials to show up in my github repo. This is what I have done so far.

// creds.js
const firebaseConfig = {
    apiKey: "myapikey",
    authDomain: "site-123.firebaseapp.com",
    projectId: "site-123",
    storageBucket: "site-123.appspot.com",
    messagingSenderId: "9999999999",
    appId: "1:1111111:web:jhg123hjjh123",
    measurementId: "G-FFFFFFFFF"
  };


export { firebaseConfig };

Now since I have exported this, I just import the credentials in my main.js file.

// main.js
import { firebaseConfig } from "./creds.js"

const firebase = initializeApp(firebaseConfig)
const database = getDatabase(firebase)

Now, is it possible to "hide" the credentials file from my github repo?
**I don't use the command-line tool or github desktop**. I tried adding the filename to my .gitignore, but the file still shows up when I visit my repo with another account.

This is what my .gitignore looks like now

# Custom
creds.js

I visited similar questions, but couldn't find a solution. Any help is appreciated. Thanks in advance!

sabz
  • 460
  • 1
  • 4
  • 10

2 Answers2

1

If creds.js was committed and pushed into the repo already, and THEN you updated the .gitignore file, then it just stays in the repository. .gitignore only has an effect on git commands that you execute, not on anything that is already in the repo.

See here for how to fix this problem afterwards: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository

Peter B
  • 22,460
  • 5
  • 32
  • 69
  • I added `kings.txt` to my gitignore and created a new file with the same name and file extension. It still shows up. This is my repo: https://github.com/sabzdotpy/sabzdotpy.github.io . – sabz Dec 15 '21 at 03:13
  • How was it added, did you manually type and then run `git add kings.txt -f`? If so, then you told git to basically *ignore .gitignore*. The .gitignore file is used when you run `git status` or `git add .` etc. The file is also used when you use an IDE such as VS Code, Visual Studio, etc. etc. so these tools will not show changes to files that they are told to ignore. – Peter B Dec 15 '21 at 08:54
  • 1
    Or did you add it by doing "Add file" on the Github.com website? That will also *ignore .gitignore*. – Peter B Dec 15 '21 at 09:00
  • Okayy I get it now. I added it with the "Add file" on github.com. So it's not possible to ignore files if I add files on the website? – sabz Dec 15 '21 at 11:46
  • No, Github will just do what you tell it to do, Github is the online repository, it will store whatever you tell it to store. Only tools *on your PC* (git, VS Code, etc) will look at `.gitignore` and will behave according to the rules that it specifies. – Peter B Dec 15 '21 at 12:06
0

If you have commited your project before adding creds.js this will not delete your file from your repo, If you want to delete it you can watch out this question.

This will not delete your creds.js from the history of your repo, so if you want to keep your data private and not having to delete the repo and create another one, you can watch out this question about Deleting your Git History instead

Martín JF
  • 152
  • 2
  • 14