Search code examples
phpgitgithubcredentialsgit-push

How to git push without credentials?


I'm new to git and github and would like to know how to git push login-credentials.php without Username and Password in it.

Suppose, there are just two files on local repository and index.php will include ("login-redentials.php");:

index.php
login-credentials.php

When using git push origin master, both files will be pushed to github. In this case, USERNAME and PASSWORD will be made published.

What is the best way to remove login credentials from login-credentials.php BEFORE using git push? - I could not find a best practice for this use case in git documentation.


Solution

  • If you want to totally ignore the files, you should add them to your .gitignore.

    If you wish to "hide" only the credentials, that depends on your deployment and your build process. One way is using a vault (again, depending on your system).

    Another option would be reading credentials from some environment variable, that'll be set in a secured manner somewhere else.