A PCRE internal error occured. This might be caused by a faulty plugin

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
packages:git [2014/05/30 00:08]
admin [Server Side Install]
packages:git [2015/05/24 18:45] (current)
admin [Creating Your Local git Copy]
Line 19: Line 19:
 ---- ----
 <​code>​ <​code>​
-sudo apt-get update +sudo apt-get update 
-sudo apt-get install git+sudo apt-get install git 
 +</​code>​ 
 + 
 +=== Create git user and repository === 
 +<​code>​ 
 +> sudo adduser git 
 +Adding user `git' ... 
 +Adding new group `git' (1001) ... 
 +Adding new user `git' (1001) with group `git' ... 
 +Creating home directory `/​home/​git'​ ... 
 +Copying files from `/​etc/​skel'​ ... 
 +Enter new UNIX password:  
 +Retype new UNIX password:  
 +passwd: password updated successfully 
 +Changing the user information for git 
 +Enter the new value, or press ENTER for the default 
 + Full Name []:  
 + Room Number []:  
 + Work Phone []:  
 + Home Phone []:  
 + Other []:  
 +Is the information correct? [Y/n] Y
 </​code>​ </​code>​
  
-=== Create git repository === 
 Create the main repository for git projects: Create the main repository for git projects:
 <​code>​ <​code>​
Line 29: Line 49:
 > cd $HOME > cd $HOME
 > mkdir <​git-projects>​ > mkdir <​git-projects>​
-> chmod 2775 <​git-projects>​ && cd <​git-projects>​+> chmod 2775 <​git-projects>​
 </​code>​ </​code>​
  
Line 37: Line 57:
 > nano .profile > nano .profile
  
-ADD:+CHANGE:
 # the default umask is set in /​etc/​profile;​ for setting the umask # the default umask is set in /​etc/​profile;​ for setting the umask
 # for ssh logins, install and configure the libpam-umask package. # for ssh logins, install and configure the libpam-umask package.
 umask 0002 umask 0002
- 
 </​code>​ </​code>​
 +
 +The umask controls the default file creation permissions,​ 0002 means files will have 664 and directories 775. Setting this, by editing the umask line in **/​etc/​profile** in our case, means files created by one user will be writable by other users in the git group without needing to chmod them.
 +
 +This solution was inspired by [[http://​serverfault.com/​questions/​6895/​whats-the-best-way-of-handling-permissions-for-apache2s-user-www-data-in-var|this post on serverfault.com]].
  
 === Add shell users === === Add shell users ===
 +Create gitusers, members of the git group and having **/​home/​git** as home
 <​code>​ <​code>​
 > sudo adduser <​gituser>​ > sudo adduser <​gituser>​
 > sudo passwd <​gituser>​ > sudo passwd <​gituser>​
 > sudo usermod -a -G git <​gituser>​ > sudo usermod -a -G git <​gituser>​
 +> sudo usermod -d /home/git <​gituser>​
 </​code>​ </​code>​
  
 +=== Using RSA keys for login ===
 +To avoid having to enter a password each time the <​gituser>​ logs in to the server, we'll register it's public RSA id key into the **.ssh/​authorized_keys** file:
  
 +First you'll have to receive the public from each one of your intended users. The public key of a user generally resides in a pair of files, under your **$HOME/​.ssh** directory, named something and something.pub,​ where the something is usually id_dsa or id_rsa. The .pub file is your public key, and the other file is your private key. If you don’t have these files (or you don’t even have a .ssh directory), you can create them by running a program called ssh-keygen, which is provided with the SSH package on Linux/Mac systems and comes with the MSysGit package on Windows:
  
-Login to server +To create a new pair of keys (on your local machine): 
-> ssh jcarlosd_los_ssh@ks307771.kimsufi.com +<​code>​ 
-mkdir private/website.git +> mkdir $HOME/​.ssh 
-> cd private/​website.git+> cd $HOME/​.ssh 
 +> ssh-keygen 
 +</​code>​ 
 + 
 +Then copy the content of the **$HOME/​.ssh/​id_rsa.pub** file to the **/​home/​git/​.ssh/​authorized_keys** file on the server. 
 + 
 +The user should now be able to login to the server using ssh without having to enter a password. 
 +---- 
 +==== Creating a Shared git Project Repository ==== 
 +---- 
 +Login to the server ​and init a bare repository:​ 
 +<​code>​ 
 +> ssh <​gituser>​@my.server.tld 
 +cd /home/​git/<​git-projects>​ 
 +> mkdir <​project-name.git> 
 +> cd <​project-name.git>
 > git init --bare > git init --bare
 +</​code>​
 +
 +=== Create hooks ===
 +git automates execution of shell scripts before or after execution of specified operations, have a look inside your project'​s "​bare"​ git repository, and look at what's inside the <​project-name.git>/​hooks directory...
 +
 +An example of what can be achieved using these scripts is to checkout the latest committed version to a specific directory right after each commit:
 +<​code>​
 > nano hooks/​post-receive > nano hooks/​post-receive
  
 +WRITE:
 #!/bin/sh #!/bin/sh
-GIT_WORK_TREE=/​var/​www/​www.lundiosoleil.com/web git checkout -f+GIT_WORK_TREE=/​var/​www/​www.mysite.com/web git checkout -f
  
 > chmod +x hooks/​post-receive > chmod +x hooks/​post-receive
 +</​code>​
  
 +----
 +==== Creating Your Local git Copy ====
 +----
  
-ON WORKSTATION +<​code>​ 
- +> cd /home/<​username>​/path/to/project
-> cd /Users/thibaut/​Documents/apache2/MAMP_htdocs/osoleil+
 > git init > git init
-> git remote add web jcarlosd_los_ssh@www.lundiosoleil.com:/var/www/www.lundiosoleil.com/​private/website.git +> git remote add <​staging>​ <​gituser>​@my.server.tld:/home/git/<​git-projects>​/<​project-name.git> 
-> git add file1 file2 dir/* +> git add <file1> <file2> <dir/*> 
-> git commit -m "​Initial commit"​ +> git commit -m <"​Initial commit"​> 
-> git push web +master:​refs/​heads/​master+> git push <​staging> ​+master:​refs/​heads/​master 
 +</​code>​ 
 + 
 +To update an existing remote: 
 + 
 +<​code>​ 
 +> git remote set-url <​staging>​ <​gituser>​@my.newserver.tld:/​home/​git/<​git-projects>/<​project-name.git>​ 
 +</​code>​ 
 + 
 +---- 
 ==== Useful Git Commands ==== ==== Useful Git Commands ====
 +----
 It isn't in the scope of this article to help you learn Git, although here are a few commands that prove themselves useful in the course of my development experience It isn't in the scope of this article to help you learn Git, although here are a few commands that prove themselves useful in the course of my development experience
  
 <wrap todo>TO BE COMPLETED</​wrap>​ <wrap todo>TO BE COMPLETED</​wrap>​