How do I prevent .gitignore from being committed?
//open file in your local project and adding files or directories
//which excluded from commiting
.git/info/exclude
How do I prevent .gitignore from being committed?
//open file in your local project and adding files or directories
//which excluded from commiting
.git/info/exclude
You like to deploy automatically our Git Project to Production or Testing System.
We create a bare Repository and a Deployment-Directory
/home/user/project/projectname (Git Repository)
/home/user/project/testsystemname (Git Repository)
/var/www/project (Working Tree – Deployment Directory)
/var/www/testsystem (Working Tree – Deployment Directory)
mkdir -p ~/projects/projectname
cd /home/user/projects/procjectname or cd ~/projects/projectname
mkdir project-name.git
git init --bare
mkdir -p ~/projects/projectname-testsystem
cd /home/user/projects/projectname-testsystem
alternativly cd ~/projects/testsystem
mkdir projectname-testsystem.git
git init --bare
2. User privileges, suggestioned the user has grant to Repository /home/user/projects/project/projectname.git
sudo chown -R `whoami`:`id -gn` /var/www/projectname
sudo chown -R `whoami`:`id -gn` /var/www/projectname-testsystem
3. Create a post-receive hook at
/home/user/projects/project-name.git/hooks/post-receive/
/home/user/projects/project-name.git/hooks/post-receive
4. Edit post-receive Hook (Production Repo)
You can customize i.e. automatically composer update Project or Backup currently Project files for Rollback possibility.
This example for Production , you can also use for Testsystem.
#!/bin/sh
NOW=$(date +'%d-%m-%Y_%T')
BACKUP=/backups/project/$NOW/
TARGET="/var/www/project"
GIT_DIR="/home/birneos/projekt/guestbook"
# backup current version, in case we need to do a rollback
echo "Create Backup form Old-Version for Rollbacks"
echo "see at $BACKUP"
cp -R /var/www/project/. "$BACKUP"
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Master ref received. Deploying master branch to production..."
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
else
echo "Ref $ref successfully received. Doing nothing: only the ${BRANCH} branch may bei deployed on this server."
fi
done
# custom steps for deployment
# For example, let's execute composer to refresh our dependencies :
cd /var/www/project
composer update
5. Make sure it is executable
chmod +x post-receive
6. Add the remote-repository to your local system
Let’s now add a reference to this bare repository to our local system, as a remote location. Let’s call this remote „production“. (It could also be called „staging“ or „live“ or „test“… should you want to deploy to a different system or to multiple systems.)
cd ~/path/to/working-copy/
$ git remote add production ssh://username@myserver.com:22/path/to/project/folder/project-name.git
OR THE ALTERNATIVE...
# ~/project/projectname (the tilde means login into home directory from user (user@remoteip)
cd ~/path/to/working-copy/
git remote add production user@remoteip:~/projekt/projectname
git remote add testsystem birneos@remoteip:~/projekt/projectname-testsystem
7. Check git remote references
git remote -v
8. Thats it. let go and pushing…
git push production master
git push testsystem master
git push staging master