Version 8 (modified by jeremyb, 6 years ago) (diff)

fix gitignore creation. a lot of this does not seem generally useful (to a wide spectrum of users). what is the goal of this page?

How to Setup Git on server

Create a Repo on Server

First thing to do is create a git repo with the command

  1. Create a repository in webroot with the command
git init

Create a .gitignore File

  1. Using a text editor, create a .gitignore file

The next thing to note is that you don't want any uploaded files or configuration files to be in the repository

in that file (for WordPress sites) add the following lines:


As a starting point, try the GitHub .gitignore template.

Can be done by:

cat <<EOF > .gitignore

Add Files to the Repo

  1. Add files to the git repository with the command
git add .

Check status with

git status

Initial Commit

  1. Do the initial commit with the command
git commit -m 'Initial Commit'

Make Bare Repo (Remote)

  1. Create a bare repository outside webroot
cd ../include && mkdir code

The run

cd code && git init --bare

Add Bare Repo as Remote

  1. Add a remote to our main git repo

From the webroot, enter the command:

git remote add code ../include/code

Push to Remote

  1. push our main repo to the remote with the command
git push code master

Set up Hooks (Optional)

  1. Add needed hooks for handling live and remote changes.
  1. Using a text editor (nano) with this command 'nano .git/hooks/post-commit.sample' (I think)

Use this code


echo "**** pushing changes to Hub [Prime's post-commit hook]"

git push code

Ctr-x then y to save hit enter

The run

mv .git/hooks/post-commit.sample .git/hooks/post-commit
  1. add post-update hook in the bare repository
nano ../include/code/hooks/post-update.sample

Add the following


echo "**** Pulling changes into Prime [Hub's post-update hook]"

cd $HOME/ || exit
unset GIT_DIR
git pull code master

exec git-update-server-info

NOTE: Change to the correct domain

change the file name with the command

mv ../include/code/hooks/post-update.sample ../include/code/hooks/post-update

Create Repo in Local Environment

  1. From local web root initialize a git repo with the command
git init

Add Remote to Local

  1. add a remote to the local repository with the command
git remote add code

NOTE: Change commnet to the correct user, to the correct server and to the correct domain

Pull in Code to Local from Remote

  1. Pull in the remote repo with the command
git pull code master