Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Nov 4, 2013

Debian: Installing gitolite

Tried setting up gitolite in Debian following my earlier guide with CentOS, but it didn't work out as well because there were a few steps missing (Debian doesn't create the gitolite user automatically). These are the modified steps:

  1. Install gitolite:
    sudo apt-get install git git-core python-setuptools gitolite
  2. Add the gitolite user (this is the user that will host the git repositories and control access):
    sudo useradd gitolite
  3. As the user who will be administrating the set-up (i.e. someone OTHER than the gitolite user), create a set of ssh keys and move them to where the gitolite user can access them:
    ssh-keygencp ~/.ssh/id_rsa.pub /tmp/admin.pub
  4. Switch to the gitolite user:
    sudo su - gitolite
  5. Run the set-up command:
    gl-setup /tmp/admin.pub
  6. As the user who will be administrating the set-up, clone the repository
    git clone gitolite@[ip address]:gitolite-admin.git
You can now add in other keys and set up the configuration of gitolite.

References:

May 15, 2013

Git: Pulling a single directory only from a remote repository

I was working with a web application that used the Laravel framework and, because big projects take time, the framework was updated mid-project. I wanted to use these updates without messing up the changes I had already made to config files. So I came up with this workaround:

git checkout laravel/master -- laravel/

So in detail, I run the 'git checkout' command with the parameter 'laravel/master'. That parameter is a reference to the remote repository 'laravel' (which I had set up earlier by running 'git remote add laravel git://github.com/laravel/laravel.git') and specifically the 'master' branch. The '--' in the command means I want to check-out a specific file or directory, which in this case means the 'laravel/' directory.

Nice, short and sweet.


Dec 1, 2012

Migrating and transfering gitolite to a new server

I am going to assume you have already installed gitolite on two servers (if you haven't, check out my guide on installing gitolite). This post will outline how you will move your repositories from one server to your new one.

The server side

  1. You can edit some of the configuration files stored in the home directory of the gitolite user. You only have to do this step if you have an unusual set-up; it should work fine if you did a default install.
  2. Copy the contents of your repositories folder to the new server (except gitolite-admin; we will do this at a later stage). Use either the commands cp or scp. For instance:
    scp -r repo.git/ root@192.168.0.1:/var/lib/gitolite/repositories/
  3. Change the owner and group of the copied repositories:
    chown -R gitolite:gitolite repo.git/
  4. Clone the gitolite configuration repository on your administration machine:
    git clone gitolite@192.168.0.1:gitolite-admin.git
  5. Add the keys and configuration files from your old repository and place them into your new repository. Do a commit and then a push:
    git add .
    git commit -as
    git push
  6. The server is now set up and ready to use! Optional: The guide quoted that you may need to run gl-setup again once the repositories have been copied across, but I didn't need to. You may want to do that step....

The client side

To point your git repository to the new server (so you don't have to reconfigure your IDE or scripts) just run the following commands:

git remote rename origin old
git remote add origin git@192.168.0.1:repo.git
git remote -v
git remote rm old

Further Reading:

Nov 30, 2012

Installing gitolite in CentOS 6

Gitolite is an management service that sits on top of git. It helps restrict users to certain projects (and what they can do on those projects). In this post we will install gitolite in a CentOS 6 environment.

  1. First we need to enable the EPEL repository. You could download and install gitolite directly, but I prefer to manage everything through the package manager for auditing purposes.
    wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm
    rpm -ivh ./epel-release-6-7.noarch.rpm
  2. Install gitolite (it will most likely install a variety of dependencies):
    yum install gitlolite
  3. If this is a brand new gitolite installation you will need to create a public SSH key on the account you will be using to administer your gitolite installation. The creation of these keys are outside the scope of this documentation. Once the key pair has been created, copy the public version to a common place where gitolite can access it (like temp). Use the command cp or scp to acheive this.
  4. Rename your copied public key with some sort of identifier. Gitolite uses the name of your keys to determine access.
  5. Log in as the gitolite user:
    su - gitolite
  6. Initialize your gitolite service with the key:
    gl-setup -q /tmp/user.pub
  7. Now you can use gitolite!
    ssh gitolite@192.168.0.1 info
    git clone gitolite@192.168.0.1:gitolite-admin.git

Further Reading:

Mar 10, 2012

Using GIT

GIT is a distributed version control system. Unlike SVN, which is centralised, each copy of a git project tree contains it's very own repository. This makes it easier to create branches and forks for development without polluting the main code trunk.

  • To start your first local git repository:
    1. Initialise the repository
      git init
    2. Add all the files in the current directory
      git add .
    3. Commit your initial import
      git commit
  • To monitor changes and logs in your code:
      1. View the revision history
        git log
      2. View the file changes in the repository
        git diff
      3. View the changes for a specific revision and file/directory path
        git diff revision path
      4. Summary of the current changes to the repository
        git status
  •  Some house cleaning functions:
      1. To add a file:
        git add file
      2. To remove a file:
        git rm file
      3. To move a file:
        git mv file
      4. To remove all untracked files (such as temporary files used during compilation):
        git clean
  •  Configure your git instance
      1. Change your username
        git config --global user.name "Your Name"
      2. Change your email
        git config --global user.email email@domain.com
  •  Common functions
      1. Clone an existing repository
        git clone url
      2. Fetch the changes from remote master repository
        git fetch
      3. Similar to above, but this command will merge the changes as well
        git pull
      4. Push your changes to a remote repository
        git push url
      5. Commit all your changes to the local repository
        git commit -a
      6. Edit your last commit with latest changes
        git commit --append
      7. Toss away your last commit
        git reset HEAD^
      8. Assign blame for problematic files
        git blame file
  • Tags and branches
      1. Tags a version
        git tag -a name
      2. List tags
        git tag -l
      3. Show the details about a tag
        git show tag
      4. Create a new branch
        git branch branch
      5. Switch to a branch
        git checkout branch
      6. Delete a branch
        git branch -d branch
      7. List all branches
        git branch
      8. Merges a branch to our current working branch
        git merge branch
 References
http://schacon.github.com/git/gittutorial.html
http://gitref.org