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!

3
  • 1
    You have to delete the file again. Commit these changes and than git will ignore the file. Commented Dec 14, 2021 at 16:17
  • 2
    @LarsFlieger This doesn't affect the history Commented Dec 14, 2021 at 16:18
  • @Andreas That's true. Maybe something like this on top: stackoverflow.com/questions/43762338/… Commented Dec 14, 2021 at 16:19

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

5 Comments

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: github.com/sabzdotpy/sabzdotpy.github.io .
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.
Or did you add it by doing "Add file" on the Github.com website? That will also ignore .gitignore.
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?
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.
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.