How to process fluky but necessary file in git?
For example, banne.gif
,config_mysql.php
.banner.gif
is necessary when coding because we need to check css layout,and designer always change it.config_mysql.php
is necessary when coding because we need this file to run mysql,and we cannot use production version
.
I am not sure whether git add
those files or put those files in .gitignore
.
What's the best way to process those kinds of files in git?
git
add a comment |
For example, banne.gif
,config_mysql.php
.banner.gif
is necessary when coding because we need to check css layout,and designer always change it.config_mysql.php
is necessary when coding because we need this file to run mysql,and we cannot use production version
.
I am not sure whether git add
those files or put those files in .gitignore
.
What's the best way to process those kinds of files in git?
git
Why can't banner.gif be inside the repository, it seems like something that is part of the appliacation and should thus be sourcce controlled together with the code?
– danielorn
Dec 31 '18 at 13:20
too many pics,too big git warehouse.
– kittygirl
Dec 31 '18 at 13:22
add a comment |
For example, banne.gif
,config_mysql.php
.banner.gif
is necessary when coding because we need to check css layout,and designer always change it.config_mysql.php
is necessary when coding because we need this file to run mysql,and we cannot use production version
.
I am not sure whether git add
those files or put those files in .gitignore
.
What's the best way to process those kinds of files in git?
git
For example, banne.gif
,config_mysql.php
.banner.gif
is necessary when coding because we need to check css layout,and designer always change it.config_mysql.php
is necessary when coding because we need this file to run mysql,and we cannot use production version
.
I am not sure whether git add
those files or put those files in .gitignore
.
What's the best way to process those kinds of files in git?
git
git
asked Dec 31 '18 at 12:31
kittygirlkittygirl
394316
394316
Why can't banner.gif be inside the repository, it seems like something that is part of the appliacation and should thus be sourcce controlled together with the code?
– danielorn
Dec 31 '18 at 13:20
too many pics,too big git warehouse.
– kittygirl
Dec 31 '18 at 13:22
add a comment |
Why can't banner.gif be inside the repository, it seems like something that is part of the appliacation and should thus be sourcce controlled together with the code?
– danielorn
Dec 31 '18 at 13:20
too many pics,too big git warehouse.
– kittygirl
Dec 31 '18 at 13:22
Why can't banner.gif be inside the repository, it seems like something that is part of the appliacation and should thus be sourcce controlled together with the code?
– danielorn
Dec 31 '18 at 13:20
Why can't banner.gif be inside the repository, it seems like something that is part of the appliacation and should thus be sourcce controlled together with the code?
– danielorn
Dec 31 '18 at 13:20
too many pics,too big git warehouse.
– kittygirl
Dec 31 '18 at 13:22
too many pics,too big git warehouse.
– kittygirl
Dec 31 '18 at 13:22
add a comment |
3 Answers
3
active
oldest
votes
Keeping environment specific configuration values outside of the source controlled code repository is generally a good idea since code should be able to run anywhere, only configuration should change.
Solution 1: Sample files
Instead of keeping config_mysql.php
inside the reposiotry keep a file called config_mysql.php.sample
and add config_mysql.php
to .gitignore
People cloning or branching out from master locally can then specify their property values config_mysql.php
, which is added to .gitignore
and thus not impacting the git tree. A developer only edits the config_mysql.php.sample
file if config is added/removed (which is information that needs to be added to the source code repository)
Solution 2: Keep configuration values in environment variables
Instead of specifying the actual values for the keys in config_mysql.php.sample
pull them from environment variables.
$db_host = $_SERVER["MYAPP_DB_HOST"];
$db_user = $_SERVER["MYAPP_DB_USER"];
// and so on
This way there is only one configuration file, which is under source control together with the code, and developers set their local values by setting environment variables. Shared enviornments like prodution and staging need to either be prepared with those environment variables or the deployment tool can take care of injecting them.
Summary
I tend to like solution 2 better, since there is no need for sample files and it is easy to override configuration). It can even be extended by providing default values if the environment variable is not set. This is not suitable for all types of configuration values and should be used with care to avoid accidental connections to for example a production database
add a comment |
There's not really one answer that's always right. It can depend on any number of things. Some very general advice follows, and you can find more information from existing questions/answers.
Image Files
If they're small and/or not frequently changing, you can consider just add
ing them and not worry too much about it. While git isn't as good at handling binary files, the main problem they cause is bloating the repository; and at moderate sizes it's not a big problem.
For the purpose you describe, you might reduce the size (and possibly the frequency of change) by using properly-dimensioned placeholders.
If image files are going to be a problem, you could use a tool like git lfs
, which keeps the repo size under control by providing a secondary repo for files like large binaries.
Environment-specific Files
My general advice is to .gitignore
these and use your build project to bring in (and/or construct) the correct version for the build's target environment. For example, you could check in a template file from which each environment's version of the file could be constructed, then have your build process fill in the template based on a variable that specifies the environment.
add a comment |
In my opinion, you can have two versions of banner.gif
and config_mysql.php
.
For example, you can check in to Git these files:
config_mysql.php
and config_mysql_dev.php
On production, use config_mysql.php
file.
And on your local machine, you can rename the file config_mysql_dev.php
to config_mysql.php
to use it.
Similar things can be thought for banner.gif...
Renamingconfig_mysql_dev.php
toconfig_mysql.php
is not very flexible as it assumes all developers use the same local setup and it will generate conflicts in pulls. It can also be dangerous as the production credentials are distributed to all developers and they are used by default ...
– danielorn
Dec 31 '18 at 13:37
Developing an application should not require credentials for the production database. If the developers also operates the application fine, they need the credentials for that purpose, but if not there should be no reason. My point is a) that your suggestion leaves no choice but to share the db credentials with anybody with access to the repository, and b) that they are used by default, if you just clone the repo and do nothing else you will connet to the production database. Those reasons are why I think your suggestion is a bad practice that should be discouraged.
– danielorn
Jan 1 at 14:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987559%2fhow-to-process-fluky-but-necessary-file-in-git%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Keeping environment specific configuration values outside of the source controlled code repository is generally a good idea since code should be able to run anywhere, only configuration should change.
Solution 1: Sample files
Instead of keeping config_mysql.php
inside the reposiotry keep a file called config_mysql.php.sample
and add config_mysql.php
to .gitignore
People cloning or branching out from master locally can then specify their property values config_mysql.php
, which is added to .gitignore
and thus not impacting the git tree. A developer only edits the config_mysql.php.sample
file if config is added/removed (which is information that needs to be added to the source code repository)
Solution 2: Keep configuration values in environment variables
Instead of specifying the actual values for the keys in config_mysql.php.sample
pull them from environment variables.
$db_host = $_SERVER["MYAPP_DB_HOST"];
$db_user = $_SERVER["MYAPP_DB_USER"];
// and so on
This way there is only one configuration file, which is under source control together with the code, and developers set their local values by setting environment variables. Shared enviornments like prodution and staging need to either be prepared with those environment variables or the deployment tool can take care of injecting them.
Summary
I tend to like solution 2 better, since there is no need for sample files and it is easy to override configuration). It can even be extended by providing default values if the environment variable is not set. This is not suitable for all types of configuration values and should be used with care to avoid accidental connections to for example a production database
add a comment |
Keeping environment specific configuration values outside of the source controlled code repository is generally a good idea since code should be able to run anywhere, only configuration should change.
Solution 1: Sample files
Instead of keeping config_mysql.php
inside the reposiotry keep a file called config_mysql.php.sample
and add config_mysql.php
to .gitignore
People cloning or branching out from master locally can then specify their property values config_mysql.php
, which is added to .gitignore
and thus not impacting the git tree. A developer only edits the config_mysql.php.sample
file if config is added/removed (which is information that needs to be added to the source code repository)
Solution 2: Keep configuration values in environment variables
Instead of specifying the actual values for the keys in config_mysql.php.sample
pull them from environment variables.
$db_host = $_SERVER["MYAPP_DB_HOST"];
$db_user = $_SERVER["MYAPP_DB_USER"];
// and so on
This way there is only one configuration file, which is under source control together with the code, and developers set their local values by setting environment variables. Shared enviornments like prodution and staging need to either be prepared with those environment variables or the deployment tool can take care of injecting them.
Summary
I tend to like solution 2 better, since there is no need for sample files and it is easy to override configuration). It can even be extended by providing default values if the environment variable is not set. This is not suitable for all types of configuration values and should be used with care to avoid accidental connections to for example a production database
add a comment |
Keeping environment specific configuration values outside of the source controlled code repository is generally a good idea since code should be able to run anywhere, only configuration should change.
Solution 1: Sample files
Instead of keeping config_mysql.php
inside the reposiotry keep a file called config_mysql.php.sample
and add config_mysql.php
to .gitignore
People cloning or branching out from master locally can then specify their property values config_mysql.php
, which is added to .gitignore
and thus not impacting the git tree. A developer only edits the config_mysql.php.sample
file if config is added/removed (which is information that needs to be added to the source code repository)
Solution 2: Keep configuration values in environment variables
Instead of specifying the actual values for the keys in config_mysql.php.sample
pull them from environment variables.
$db_host = $_SERVER["MYAPP_DB_HOST"];
$db_user = $_SERVER["MYAPP_DB_USER"];
// and so on
This way there is only one configuration file, which is under source control together with the code, and developers set their local values by setting environment variables. Shared enviornments like prodution and staging need to either be prepared with those environment variables or the deployment tool can take care of injecting them.
Summary
I tend to like solution 2 better, since there is no need for sample files and it is easy to override configuration). It can even be extended by providing default values if the environment variable is not set. This is not suitable for all types of configuration values and should be used with care to avoid accidental connections to for example a production database
Keeping environment specific configuration values outside of the source controlled code repository is generally a good idea since code should be able to run anywhere, only configuration should change.
Solution 1: Sample files
Instead of keeping config_mysql.php
inside the reposiotry keep a file called config_mysql.php.sample
and add config_mysql.php
to .gitignore
People cloning or branching out from master locally can then specify their property values config_mysql.php
, which is added to .gitignore
and thus not impacting the git tree. A developer only edits the config_mysql.php.sample
file if config is added/removed (which is information that needs to be added to the source code repository)
Solution 2: Keep configuration values in environment variables
Instead of specifying the actual values for the keys in config_mysql.php.sample
pull them from environment variables.
$db_host = $_SERVER["MYAPP_DB_HOST"];
$db_user = $_SERVER["MYAPP_DB_USER"];
// and so on
This way there is only one configuration file, which is under source control together with the code, and developers set their local values by setting environment variables. Shared enviornments like prodution and staging need to either be prepared with those environment variables or the deployment tool can take care of injecting them.
Summary
I tend to like solution 2 better, since there is no need for sample files and it is easy to override configuration). It can even be extended by providing default values if the environment variable is not set. This is not suitable for all types of configuration values and should be used with care to avoid accidental connections to for example a production database
answered Dec 31 '18 at 13:19
danielorndanielorn
1937
1937
add a comment |
add a comment |
There's not really one answer that's always right. It can depend on any number of things. Some very general advice follows, and you can find more information from existing questions/answers.
Image Files
If they're small and/or not frequently changing, you can consider just add
ing them and not worry too much about it. While git isn't as good at handling binary files, the main problem they cause is bloating the repository; and at moderate sizes it's not a big problem.
For the purpose you describe, you might reduce the size (and possibly the frequency of change) by using properly-dimensioned placeholders.
If image files are going to be a problem, you could use a tool like git lfs
, which keeps the repo size under control by providing a secondary repo for files like large binaries.
Environment-specific Files
My general advice is to .gitignore
these and use your build project to bring in (and/or construct) the correct version for the build's target environment. For example, you could check in a template file from which each environment's version of the file could be constructed, then have your build process fill in the template based on a variable that specifies the environment.
add a comment |
There's not really one answer that's always right. It can depend on any number of things. Some very general advice follows, and you can find more information from existing questions/answers.
Image Files
If they're small and/or not frequently changing, you can consider just add
ing them and not worry too much about it. While git isn't as good at handling binary files, the main problem they cause is bloating the repository; and at moderate sizes it's not a big problem.
For the purpose you describe, you might reduce the size (and possibly the frequency of change) by using properly-dimensioned placeholders.
If image files are going to be a problem, you could use a tool like git lfs
, which keeps the repo size under control by providing a secondary repo for files like large binaries.
Environment-specific Files
My general advice is to .gitignore
these and use your build project to bring in (and/or construct) the correct version for the build's target environment. For example, you could check in a template file from which each environment's version of the file could be constructed, then have your build process fill in the template based on a variable that specifies the environment.
add a comment |
There's not really one answer that's always right. It can depend on any number of things. Some very general advice follows, and you can find more information from existing questions/answers.
Image Files
If they're small and/or not frequently changing, you can consider just add
ing them and not worry too much about it. While git isn't as good at handling binary files, the main problem they cause is bloating the repository; and at moderate sizes it's not a big problem.
For the purpose you describe, you might reduce the size (and possibly the frequency of change) by using properly-dimensioned placeholders.
If image files are going to be a problem, you could use a tool like git lfs
, which keeps the repo size under control by providing a secondary repo for files like large binaries.
Environment-specific Files
My general advice is to .gitignore
these and use your build project to bring in (and/or construct) the correct version for the build's target environment. For example, you could check in a template file from which each environment's version of the file could be constructed, then have your build process fill in the template based on a variable that specifies the environment.
There's not really one answer that's always right. It can depend on any number of things. Some very general advice follows, and you can find more information from existing questions/answers.
Image Files
If they're small and/or not frequently changing, you can consider just add
ing them and not worry too much about it. While git isn't as good at handling binary files, the main problem they cause is bloating the repository; and at moderate sizes it's not a big problem.
For the purpose you describe, you might reduce the size (and possibly the frequency of change) by using properly-dimensioned placeholders.
If image files are going to be a problem, you could use a tool like git lfs
, which keeps the repo size under control by providing a secondary repo for files like large binaries.
Environment-specific Files
My general advice is to .gitignore
these and use your build project to bring in (and/or construct) the correct version for the build's target environment. For example, you could check in a template file from which each environment's version of the file could be constructed, then have your build process fill in the template based on a variable that specifies the environment.
answered Dec 31 '18 at 13:23
Mark AdelsbergerMark Adelsberger
20.6k11321
20.6k11321
add a comment |
add a comment |
In my opinion, you can have two versions of banner.gif
and config_mysql.php
.
For example, you can check in to Git these files:
config_mysql.php
and config_mysql_dev.php
On production, use config_mysql.php
file.
And on your local machine, you can rename the file config_mysql_dev.php
to config_mysql.php
to use it.
Similar things can be thought for banner.gif...
Renamingconfig_mysql_dev.php
toconfig_mysql.php
is not very flexible as it assumes all developers use the same local setup and it will generate conflicts in pulls. It can also be dangerous as the production credentials are distributed to all developers and they are used by default ...
– danielorn
Dec 31 '18 at 13:37
Developing an application should not require credentials for the production database. If the developers also operates the application fine, they need the credentials for that purpose, but if not there should be no reason. My point is a) that your suggestion leaves no choice but to share the db credentials with anybody with access to the repository, and b) that they are used by default, if you just clone the repo and do nothing else you will connet to the production database. Those reasons are why I think your suggestion is a bad practice that should be discouraged.
– danielorn
Jan 1 at 14:06
add a comment |
In my opinion, you can have two versions of banner.gif
and config_mysql.php
.
For example, you can check in to Git these files:
config_mysql.php
and config_mysql_dev.php
On production, use config_mysql.php
file.
And on your local machine, you can rename the file config_mysql_dev.php
to config_mysql.php
to use it.
Similar things can be thought for banner.gif...
Renamingconfig_mysql_dev.php
toconfig_mysql.php
is not very flexible as it assumes all developers use the same local setup and it will generate conflicts in pulls. It can also be dangerous as the production credentials are distributed to all developers and they are used by default ...
– danielorn
Dec 31 '18 at 13:37
Developing an application should not require credentials for the production database. If the developers also operates the application fine, they need the credentials for that purpose, but if not there should be no reason. My point is a) that your suggestion leaves no choice but to share the db credentials with anybody with access to the repository, and b) that they are used by default, if you just clone the repo and do nothing else you will connet to the production database. Those reasons are why I think your suggestion is a bad practice that should be discouraged.
– danielorn
Jan 1 at 14:06
add a comment |
In my opinion, you can have two versions of banner.gif
and config_mysql.php
.
For example, you can check in to Git these files:
config_mysql.php
and config_mysql_dev.php
On production, use config_mysql.php
file.
And on your local machine, you can rename the file config_mysql_dev.php
to config_mysql.php
to use it.
Similar things can be thought for banner.gif...
In my opinion, you can have two versions of banner.gif
and config_mysql.php
.
For example, you can check in to Git these files:
config_mysql.php
and config_mysql_dev.php
On production, use config_mysql.php
file.
And on your local machine, you can rename the file config_mysql_dev.php
to config_mysql.php
to use it.
Similar things can be thought for banner.gif...
answered Dec 31 '18 at 13:27
nileshkumarnileshkumar
1548
1548
Renamingconfig_mysql_dev.php
toconfig_mysql.php
is not very flexible as it assumes all developers use the same local setup and it will generate conflicts in pulls. It can also be dangerous as the production credentials are distributed to all developers and they are used by default ...
– danielorn
Dec 31 '18 at 13:37
Developing an application should not require credentials for the production database. If the developers also operates the application fine, they need the credentials for that purpose, but if not there should be no reason. My point is a) that your suggestion leaves no choice but to share the db credentials with anybody with access to the repository, and b) that they are used by default, if you just clone the repo and do nothing else you will connet to the production database. Those reasons are why I think your suggestion is a bad practice that should be discouraged.
– danielorn
Jan 1 at 14:06
add a comment |
Renamingconfig_mysql_dev.php
toconfig_mysql.php
is not very flexible as it assumes all developers use the same local setup and it will generate conflicts in pulls. It can also be dangerous as the production credentials are distributed to all developers and they are used by default ...
– danielorn
Dec 31 '18 at 13:37
Developing an application should not require credentials for the production database. If the developers also operates the application fine, they need the credentials for that purpose, but if not there should be no reason. My point is a) that your suggestion leaves no choice but to share the db credentials with anybody with access to the repository, and b) that they are used by default, if you just clone the repo and do nothing else you will connet to the production database. Those reasons are why I think your suggestion is a bad practice that should be discouraged.
– danielorn
Jan 1 at 14:06
Renaming
config_mysql_dev.php
to config_mysql.php
is not very flexible as it assumes all developers use the same local setup and it will generate conflicts in pulls. It can also be dangerous as the production credentials are distributed to all developers and they are used by default ...– danielorn
Dec 31 '18 at 13:37
Renaming
config_mysql_dev.php
to config_mysql.php
is not very flexible as it assumes all developers use the same local setup and it will generate conflicts in pulls. It can also be dangerous as the production credentials are distributed to all developers and they are used by default ...– danielorn
Dec 31 '18 at 13:37
Developing an application should not require credentials for the production database. If the developers also operates the application fine, they need the credentials for that purpose, but if not there should be no reason. My point is a) that your suggestion leaves no choice but to share the db credentials with anybody with access to the repository, and b) that they are used by default, if you just clone the repo and do nothing else you will connet to the production database. Those reasons are why I think your suggestion is a bad practice that should be discouraged.
– danielorn
Jan 1 at 14:06
Developing an application should not require credentials for the production database. If the developers also operates the application fine, they need the credentials for that purpose, but if not there should be no reason. My point is a) that your suggestion leaves no choice but to share the db credentials with anybody with access to the repository, and b) that they are used by default, if you just clone the repo and do nothing else you will connet to the production database. Those reasons are why I think your suggestion is a bad practice that should be discouraged.
– danielorn
Jan 1 at 14:06
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987559%2fhow-to-process-fluky-but-necessary-file-in-git%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why can't banner.gif be inside the repository, it seems like something that is part of the appliacation and should thus be sourcce controlled together with the code?
– danielorn
Dec 31 '18 at 13:20
too many pics,too big git warehouse.
– kittygirl
Dec 31 '18 at 13:22