Git - Exclude a config file from post-receive checkout - php

I have a git project that I'm working on locally. It's a PHP project with a config file that stores MySQL database connection information. My local MySQL settings are different from the remote settings.
On my remote, I have a post-receive hook that will checkout the files to a folder on the server:
#!/bin/sh
GIT_WORK_TREE="../demo" git checkout -f
chmod +x hooks/post-receive
How can I tell this checkout not to include (overwrite the config file), since it will replace the remote config file with my local one? I've tried adding my local config file to the .gitignore, but that didn't seem to do it.
Any idea how to exclude the config file from the checkout?

The proper solution is not committing your config.php (or whatever its name is) at all but rather putting it in the .gitignore and committing config.php.example instead.
So, simply remove the config file from the repository, rename it on your remote machine, pull so you have the newest commit (which would remove the file) and then move it back.

You can try this
Running command:
git rm -r --cached .
This removes everything from the index, then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"

Related

Git::Windows: pull case sensitive files from remote repo

In my remote repository I have files,
example,
-account.php
-Account.php
To see how exactly my repository looks like,
I am now using windows git bash to clone/pull the files from remote repo.
While doing that only
-account.php
gets cloned, while
-Account.php
is being ignored!
How do I get both the files,
-account.php
-Account.php
into my local repository, so that I can delete them and make a clean commit of files with only one naming convention and eliminate the mistake I have done?
Since git is a unix based it simply a case sensitive software.
If you have committed a case sensitive files you will need to rename them. Using the git mv command will tell git to rename the file while keeping all the history of the file
# "move" the file from the old name to the new name
git mv -f File file
# Add the file to the staging area
git add .
# commit your changes
git commit -m "renamed file..."
Git has a configuration setting core.ignorecase.
To tell Git to be case-senstive, simply set this setting to false:
git config core.ignorecase false
Documentation
From the git config documentation:
core.ignorecase
If true, this option enables various workarounds to enable git to work better on filesystems that are not case sensitive, like FAT.
For example, if a directory listing finds makefile when git expects Makefile, git will assume it is really the same file, and continue to remember it as Makefile.
The default is false, except git-clone(1) or git-init(1) will probe and set core.ignorecase true if appropriate when the repository is created.

Uploading Single image in a git directory

I have created my project repository on git. Its a web development project. I want to upload a file to it.
For other kind of files (.txt, .php, .html, etc.) I know I can create a new file by clicking on + button and then copying my file's content there.
How can I upload an image to the specific directory (./img in my case). I have searched a lot but didn't got any suitable answer.
You can use this method if You are a beginner.
You can add files using git add, example git add README, git add /*, or even git add *
Then use git commit -m "" to commit files
Finally git push -u origin master to push files.
When you make modifications run git status which gives you the list of files modified, add them using git add * for everything or you can specify each file individually, then git commit -m and finally, git push -u origin master
Example - say you created a file README, running git status gives you
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# README
Source :: How do I add files and folders into github repos?

Directory Permission Problems When I Deploy PHP Script on Openshift

I am deploy a cf image host 1.6.5 on Openshift using Git. Some of the directories do not have write permission when I running installer script.
The cf image host 1.6.1 installer script will generate a setting file in a directory called "inc".
I have done git push for the zip file of cf image host 1.6.5(says cf_image_1.6.5.zip) onto Openshift using git,and unziped this file to app-root/repo/php directory. The installer script can run okay. If I unzip file at local machine, git add and git commit and git push,the setting file can not be generated in the directory inc. If I manually change permission to 777, it is okay.
But I check the file using ls -la, both two methods' the owner is myself.
How do I deploy the process work when git push? Which user of the remote machine is deploying these scripts?
Try something along this (adjust permissions)
git update-index --chmod=+w -- $(git ls-files folder/with/wrong/permissions/*)
and add, commit and push.
Deploy should happen under your default openshift user. (See uder Webinterface->App: Userpart of the ssh-git url displayed there.

PHP SVN: What's the best way to deploy svn tag to production?

What's the best way to deploy an SVN tag to production? SVN switch or SVN Checkout?
Using SVN switch will add .svn files that may consume large storage space but it is convenient and easier to use.
Using SVN Checkout will remove the .svn files and just symlink it to the newly checkout folder.
What are the pros and cons between SVN switch and SVN checkout deployment to production? Which is easier and practical to use? For me the "SVN Checkout" way.
Thanks.
Option 1: USING SVN SWITCH - SSH to production server then do SVN SWITCH like this:
$ cd /var/www/html/sites/mydomain.com/
$ svn switch https://svn.svndomain.com/repos/mydomain.com/site/tags/4.11.0-qa1
// Reload Apache
$ /etc/init.d/httpd reload
OR
Option 2: USING SVN EXPORT - SSH to production server then do SVN export to a new folder with version and symlink it like this:
// Export Site
$ svn export https://svn.svndomain.com/repos/mydomain.com/site/tags/4.11.0 /var/www/html/sites/mydomain.com_4.11.0
$ cd /var/www/html/sites/;
$ unlink mydomain.com;
$ ln -s mydomain.com_4.11.0 mydomain.com;
// Reload Apache
$ /etc/init.d/httpd reload
Use svn checkout to a new, empty directory, to make sure you don't have any non-committed file. Then use svn export to a new empty directory (or remove all the .svn directories manually). Then replace the old contents of the web-served directory with the new files, or use a symlink. .svn directories shouldn't be accessible from the outside.
My web apps usually need some build process before being deployed. This build process replaces the svn export phase.

Capistrano uploads the .git directory

I am using git with capistrano.
I initialized my project inside my folder on my local machine as such:
git init
I then pushed the project the server directory
I then called cap deploy
The deploy works, except that it uploads the local .git folder structure, as well as my .gitignore and Capfile to a publicly accessible folder.
Here's my gitignore file:
.DS_Store
uploads/**/*
Capfile
.gitignore
.git/**/*
This doesn't seem to do the trick. Any help?
Thanks!
Edit: updated .gitignore file:
Changed deployment strategy to export:
set :deploy_via, :export
This works for ignoring the .git folder, but the contents of my .gitignore file seen below are still not taken into account
.DS_Store
includes/php/config.php
/uploads
Capfile
.git
EDIT 2 (Solution): Edit 1 in combination with the following did the trick.
Files that were already added prior to being listed in the .gitignore file would constantly be uploaded. Say I had the following .gitignore file.
.DS_Store
includes/php/config.php
Then I ran the following commands:
git add .
git commit -a -m 'some commit'
Then I decided to add to my .gitignore file so it now looks like this:
.DS_Store
includes/php/config.php
Capfile
Then again, I ran:
git add .
git commit -a -m 'another commit'
Now I'd see that .DS_Store and includes/php/config.php have not been uploaded, but that the Capfile has... This is what happened to me in my original question.
The reason: I think the .gitignore file is taken into account only when adding (i.e. git add .). If I already added files, then put them in the .gitignore file, they would have already been added to the project. I'd need to use the git rm command to remove them.
I just started anew with a new .git repo and that solved the problem, but you don't have to - you can just remove whatever files you already added but now want to ignore with the git rm command.
I selected the answer that helped me get to this conclusion as the right one, though the complete solution was just detailed above.
What is your deploy strategy?
Do you have Capistrano setup to exclude the .git file?
if you are using set :deploy_via, :copy then make sure to add the following:
set :copy_exclude, [".git/*", ".svn/*", ".DS_Store"]
Otherwise use set :deploy_via, :export which should ignore your source control folders
http://www.capify.org/index.php/Understanding_Deployment_Strategies
Looking at a similar question, it appears you don't need the wild card selectors and can just have:
uploads/
You need to deploy via :git in Capistrano and do an export. It's essentially a git clone and then just deletes the .git directory afterwards.
Your problem isn't much to do with Cap really. Make sure your .gitignore file is working correctly.

Categories