简体   繁体   中英

github - How to hide a single file from repository

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!

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM