Affichage des articles dont le libellé est Git. Afficher tous les articles
Affichage des articles dont le libellé est Git. Afficher tous les articles

mercredi 11 décembre 2013

How to add git remote repository on server

first you connect ssh to your server, then you can set up an empty repository for them by running git init with the --bare option, which initializes the repository without a working directory:

$ cd /var/www/GIT_REPOSITORY
$ mkdir newRemoteProject
$ cd newRemoteProject
$ git --bare init


then you should change the permission into this new remote repository
$chmod -R 777 /var/www/GIT_REPOSITORY/newRemoteProject

Then,all team can push the first version of their project into that repository by adding it as a remote and pushing up a branch. Note that someone must shell onto the machine and create a bare repository every time you want to add a project.

# on Johns computer
$ cd myproject
$ git init
$ git add .
$ git commit -m 'initial commit'
$ git remote add origin http://Server_Adresse/GIT_REPOSITORY/newRemoteProject
$ git push origin master

Note : the path to the remote repository is under /www because i have used gitweb with git over http.

mercredi 3 juillet 2013

Restore Deleted Files using Git


Sometime you can delete a file  ,by accident, and then you commit your changes . after a while you recognize that you need this file So what you can do ??
what I have tried to resolve such problem (there are several ways) is  this few steps :
  1. List all files that have been deleted from my git repository :
    git log --diff-filter=D --summary
    
    
  2. Search the commit where you deleted your file
  3. undo your commit to the searched one BUT don't lose your modifications by taping this cmd :
    git reset --soft HEAD~n   
    

    n: is the number of undo commit steps

  4. if you type  git status  you will re-view your deleted file so to get the file back type this cmd :
    git checkout -- [file name]
    
Hope this could helps someone :D

mercredi 26 juin 2013

Git Over Http




How To use the http protocol to manage git traffic ?


Traditionally git used to work only over ssh or git protocols while there was only a dumb version of git over http which was slow and inefficient.
While this was ok for most of the time sometimes git needs to be able to work over http. 
Now starting from git 1.7 both git servers and clients have support for smart http which works over http(s) and is supposed to be as efficient as the ssh version.



the git-http-backend tool

This functionality is made available by a cgi script called git-http-backend provided with git-core.
So for git to work over http(s) there should be a web server already configured and as a result there won’t be any conflicts by both the web server and git trying acquire port 80.

Configuration

The following steps can be used to configure git to work over http(s) with Apache.

Apache Configuration

Make sure mod_cgi, mod_alias, and mod_env are enabled. to activate the WEBDAV module just use this command :
a2enmod dav_fs
1) Open the Apache config file
2) Append the following. Debian based system should have it under /etc/apache2/apache2.conf by default : SetEnv GIT_PROJECT_ROOT /home/user/git_pub SetEnv GIT_HTTP_EXPORT_ALL ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
The GIT_PROJECT_ROOT should point to the root folder where git repositories would be hosted.
Set this away from the document root of the web server. What the above do is direct any requests with /git/ to the git-http-backend and tell the script that the root of git repositories is GIT_PROJECT_ROOT.
That is all that needs to be done that is specific to git over http(s). The manual for for the git-http-backend explains these steps pretty thoroughly. Now for some tit-bits that are not explained in the manual. Those who are experienced with Apache and Git would find the following very boring.
3) User Righs
For authentication for both read and write accesses append the following to the Apache config file /etc/apache2/apache2.conf :
$  <Location /git>

$  AuthType Basic

$  AuthName “Private Git Access”

$  AuthUserFile /etc/apache2/authusers
 
$  Require valid-user

$  </Location>

What the above do is make requests to /git only accessible to valid users and tell valid users are listed on the file /etc/apache2/authusers. Make sure the file authusers is accessible by Apache. If there is no AuthUserFile in your system the following command can be used to create the user list at /etc/apache2/authusers and add the user ‘username’ to it. The command will prompt for a password for the user :
$ htpasswd -c /etc/apache2/authusers username
4) Restart Apache
On debian most probably :
$ sudo /etc/init.d/apache2 restart

Git Over Http Example

1) Create an empy bare git repository under the specified GIT_PROJECT_ROOT (/home/user/git_pub in our example) :
$ cd to GIT_PROJECT_ROOT
$ mkdir project
$ cd project
$ git init –bare
2) Make the folder ‘project’ and it’s children owned by the user which the web server is run from. This should be done for push requests by clients to work or otherwise the web server won’t be able to merge files.
On debian based systems this user is usually www-data and is defined in a file called envvars under apache2 installation :
$ sudo chown -R www-data project/
$ sudo chgrp -R www-data project/
Now the bare git repository should be pull-able and pushable by authorized users.
3) Clone the git repository over http(s) from another location:
$ git clone http://username@host/git/project
4) Do the first commit:
$ cd project
$ touch readme
$ git add readme
$ git commit -m “first commit”
$ git push origin master

dimanche 23 juin 2013

How to git ignore files that are already tracked

for all people who use  eclipse , they always don't want to track some kind of files like (.properties,.metadata ...) that are automatically created by eclipse .
also the other problem is that git will not ignore a file that was already tracked before a rule was added to the file  .gitignore to ignore it 

So what is the Solution ?

In such a case , you should follow these two steps :
    1. files must be un-tracked, usually with 
      git rm --cached filename
    2. now they do not show up as "changed" but still show as untracked files in git status , so add some  exclude rules into .git/info/exclude  file in your repository
       
In case of Eclipse ,  do these two steps  to completely remove files and repositories from being tracked :
  1. execute this script after git add . :
    git rm --cached *.pydevproject
    git rm --cached *.project
    git rm --cached *.metadata
    git rm --cached */bin/**
    git rm --cached */tmp/**
    git rm --cached *.tmp
    git rm --cached *.bak
    git rm --cached *.swp
    git rm --cached *~.nib
    git rm --cached *local.properties
    git rm --cached *.classpath
    git rm --cached *.settings/*
    git rm --cached *.loadpath
    git rm --cached *org.eclipse.wst.common.component
    git rm --cached *org.eclipse.wst.common.project.facet.core.xml
    git rm --cached *.properties
    git rm --cached *.orig
    git rm --cached *.classpath
    git rm --cached *.xml
    git rm --cached *.jar
    git rm --cached *.class
    

  2. add this code to .git/info/exclude  file in your repository
    # git ls-files --others --exclude-from=.git/info/exclude
    # Lines that start with '#' are comments.
    # For a project mostly in C, the following would be a good set of
    # exclude patterns (uncomment them if you want to use them):
    # *.[oa]
    # *~
    
    #Eclipse#
    ###################
     
    *.pydevproject
    *.project
    *.metadata
    */bin/*
    */bin/
    */tmp/**
    *.tmp
    *.bak
    *.swp
    *~.nib
    *local.properties
    *.classpath
    *.settings/*
    *.settings/
    *.loadpath
    *org.eclipse.wst.common.component
    *org.eclipse.wst.common.project.facet.core.xml
    *.properties
    *.orig
    *.classpath
    *.xml
    
    # Package Files #
    ##################
    *.jar
    *.war
    *.ear
    
    # Compiled source #
    ###################
    *.com
    *.class
    *.dll
    *.exe
    *.o
    *.so
    
    # Packages #
    ############
    # it's better to unpack these files and commit the raw source
    # git has its own built in compression methods
    *.7z
    *.dmg
    *.gz
    *.iso
    *.jar
    *.rar
    *.tar
    *.zip
    
    # Logs and databases #
    ######################
    *.log
    *.sqlite
    
    # OS generated files #
    ######################
    .DS_Store
    .DS_Store?
    ._*
    .Spotlight-V100
    .Trashes
    Icon?
    ehthumbs.db
    Thumbs.db
    
These rules are not committed with the repository so they are not shared with others. This method can be used for locally-generated files that you don't expect other users to generate, like files created by your editor.

for more informations visit the official github site.



I hope that this sample tutorial can help someone else :)