| 1 | == How to Setup Git on server == |
| 2 | |
| 3 | First thing to do is create a git repo with the command |
| 4 | |
| 5 | 1. Create a repository in webroot with the command |
| 6 | |
| 7 | {{{ |
| 8 | git init |
| 9 | }}} |
| 10 | |
| 11 | 2. Using a text editor, create a .gitignore file |
| 12 | |
| 13 | The next thing to note is that you don't want any uploaded files or configuration files to be in the repository |
| 14 | |
| 15 | in that file (for WordPress sites) add the following lines: |
| 16 | |
| 17 | {{{ |
| 18 | /wp-content/uploads |
| 19 | /wp-config.php |
| 20 | *~ |
| 21 | /.htaccess |
| 22 | }}} |
| 23 | |
| 24 | Can be done by: |
| 25 | |
| 26 | |
| 27 | {{{ |
| 28 | echo "/wp-content/uploads |
| 29 | }}} |
| 30 | |
| 31 | |
| 32 | click enter |
| 33 | |
| 34 | Add |
| 35 | {{{ |
| 36 | /wp-config.php |
| 37 | }}} |
| 38 | |
| 39 | |
| 40 | click enter |
| 41 | |
| 42 | add |
| 43 | |
| 44 | {{{ |
| 45 | " >> .gitignore |
| 46 | }}} |
| 47 | |
| 48 | |
| 49 | click enter |
| 50 | |
| 51 | Also add |
| 52 | |
| 53 | |
| 54 | {{{ |
| 55 | echo ".htaccess" >> .gitignore |
| 56 | }}} |
| 57 | |
| 58 | |
| 59 | 3. Add files to the git repository with the command |
| 60 | |
| 61 | {{{ |
| 62 | git add . |
| 63 | }}} |
| 64 | |
| 65 | |
| 66 | Check status with |
| 67 | |
| 68 | {{{ |
| 69 | git status |
| 70 | }}} |
| 71 | |
| 72 | 4. Do the initial commit with the command |
| 73 | |
| 74 | |
| 75 | {{{ |
| 76 | git commit -am"Initial Commit" |
| 77 | }}} |
| 78 | |
| 79 | |
| 80 | 5. Create a bare repository outside webroot |
| 81 | |
| 82 | for example |
| 83 | |
| 84 | {{{ |
| 85 | cd ../include && mkdir code |
| 86 | }}} |
| 87 | |
| 88 | The run |
| 89 | |
| 90 | {{{ |
| 91 | cd code && git init --bare |
| 92 | }}} |
| 93 | |
| 94 | |
| 95 | 6. Add a remote to our main git repo with the command |
| 96 | |
| 97 | |
| 98 | {{{ |
| 99 | git remote add code ../include/code |
| 100 | }}} |
| 101 | |
| 102 | |
| 103 | 7. push our main repo to the remote with the command |
| 104 | |
| 105 | |
| 106 | {{{ |
| 107 | git push code master |
| 108 | }}} |
| 109 | |
| 110 | |
| 111 | 8. Add needed hooks for handling live and remote changes. |
| 112 | |
| 113 | A. Using a text editor (nano) with this command 'nano .git/hooks/post-commit.sample' (I think) |
| 114 | |
| 115 | Use this code |
| 116 | |
| 117 | |
| 118 | {{{ |
| 119 | #!/bin/sh |
| 120 | |
| 121 | echo |
| 122 | echo "**** pushing changes to Hub [Prime's post-commit hook]" |
| 123 | echo |
| 124 | |
| 125 | git push code |
| 126 | }}} |
| 127 | |
| 128 | |
| 129 | Ctr-x |
| 130 | then y to save |
| 131 | hit enter |
| 132 | |
| 133 | The run |
| 134 | |
| 135 | {{{ |
| 136 | mv .git/hooks/post-commit.sample .git/hooks/post-commit |
| 137 | }}} |
| 138 | |
| 139 | |
| 140 | B. add post-update hook in the bare repository |
| 141 | |
| 142 | |
| 143 | {{{ |
| 144 | nano ../include/code/hooks/post-update.sample |
| 145 | }}} |
| 146 | |
| 147 | |
| 148 | Add the following |
| 149 | |
| 150 | |
| 151 | {{{ |
| 152 | #!/bin/sh |
| 153 | |
| 154 | echo |
| 155 | echo "**** Pulling changes into Prime [Hub's post-update hook]" |
| 156 | echo |
| 157 | |
| 158 | |
| 159 | cd $HOME/cn.glocal.coop/web || exit |
| 160 | unset GIT_DIR |
| 161 | git pull code master |
| 162 | |
| 163 | exec git-update-server-info |
| 164 | }}} |
| 165 | |
| 166 | change the file name with the command |
| 167 | |
| 168 | {{{ |
| 169 | mv ../include/code/hooks/post-update.sample ../include/code/hooks/post-update |
| 170 | }}} |
| 171 | |
| 172 | |
| 173 | 9. From local web root initialize a git repo with the command |
| 174 | |
| 175 | {{{ |
| 176 | git init |
| 177 | }}} |
| 178 | |
| 179 | |
| 180 | A. add a remote to the local repository with the command |
| 181 | |
| 182 | |
| 183 | {{{ |
| 184 | git remote add code commnet@rose.mayfirst.org:cn.glocal.coop/include/code |
| 185 | }}} |
| 186 | |
| 187 | |
| 188 | B. Pull in the remote repo with the command |
| 189 | |
| 190 | |
| 191 | {{{ |
| 192 | git pull code master |
| 193 | }}} |
| 194 | |