Exporting all the commits from git after a certain date

Problem

You would like to export all the commit comments from your git repository into a text file, after a certain date (ie the last live deployment date).

Solution

Use the git log option with the after parameter and redirect the output to a text file like:

git log --after="2012-05-14" --pretty=oneline >> /path/to/file/for/the/commits/export.txt

Some more useful options can be found here

Find out the repositories permissions in gitolite

Problem

You would like to know what permission and for which repositories you have as a certain user when using gitolite to host your repositories.

Solution

Assuming that your gitolite user is gitolite and you have two different servers (server_a and server_b) with two different users (deploy_a and deploy_b) you can find out the permsissions by running the following:

$server_a/deploy_a: ssh gitolite@git_host info

$server_b/deploy_b: ssh gitolite@git_host info

Using gitolite in a non standard ssh port

Problem
You have moved your gitolite server or you want to be able to access your gitolite server behind a firewall and port 22 for ssh is no longer available.

Solution
Edit your .git/config file and replace the line with :

url = git_user_name@http://server_ip:repo_name.git

to the following:

url = ssh://git_user_name@external_ip:non_standard_ssh_port/repo_name.git

.gitignore seems that is not working

Problem
Your .gitignore file seems that is not working. You have added files there like db/schema.rb, but it keeps tracking the changes to it.

Solution
The cause is that the file was added to git version control before it was added in the .gitignore file. To remove the file from git tracking but without removing it from the filesystem use the following:
$ git rm --cached filename_not_to_be_tracked

Gitweb access to gitolite repository

Problem
You are trying to set up gitolite access through gitweb but the gitweb page, shows ‘no projects avaiable’ even though you have repositories available.

Solution
Try to follow the guide here.
Some of tthe most important steps for having the right access permissions are:

  • Add the www-data user in the gitolite group by:
    $ sudo usermod -a -G gitolite www-data
  • Add the paths to the repositories and the projects list:
    $ sudo vi /etc/gitweb.conf
    $projectroot ="/var/lib/gitolite/repositories";
    $projects_list="/var/lib/gitolite/projects.list";
  • Change the permissions in the repositories:
    $ sudo chmod g+r /var/lib/gitolite/projects.list
    $ sudo chmod -R g+rx /var/lib/gitolite/repositories
  • Change permissions in the /var/lib/gitolite/.gitolite.rc file to allow access to the repositories:
    $REPO_UMASK = 0027;
  • Finally change the git-daemon to run with the gitolite group permissions in the file /etc/sv/git-daemon/run:
    exec chpst -ugitdaemon:gitolite

Upgrading your Rails 3.0.3 application

Problem
After the announcements in the previous posts about the security vulnerabilities in Rails 3.0.3, you would like to update your application and deploy with the latest 3.0.4 version.

Solution

  • Change your Gemfile to replace
    gem 'rails', '3.0.3'
    with
    gem 'rails', '3.0.4'
  • Run:
    bundle update rails
  • Remove the old gems by using:
    git status
    and then
    git rm name_of_3.0.3_gem
  • Add the new gems to your git
    git add vendor/cache
  • Check in to your repository the new files
    git commit vendor/cache -m 'upgrade to rails 3.0.4'
  • Make sure that you also check in both your Gemfile and Gemfile.lock into your git repository
    git commit Gemfile Gemfile.lock -m 'update Gemfiles to use 3.0.4'
    otherwise when you try to deploy you will see the error:
    You have modified your Gemfile in development but did not check the resulting snapshot (Gemfile.lock) into version control
  • push everything to your git repository:
    git push
  • Deploy your application with capistrano as usual:
    cap deploy
  • Your new gems for 3.0.4 should be installed on the share/bundle folder

Creating a new git repository in Gitorious

Problem
You would like to host a new git repository in Gitorius.

Solution
Assuming that you have created your initial ruby on rails application, and you have git installed, you can follow the steps below:

  1. Create a new account in Gitorious
  2. Copy your public ssh key (usually in ~./ssh) to your new account in Gitorius
  3. Create a new project in Gitorius (ie My Project)
  4. Add a new repository in Gitorius (ie My Git Repository)
  5. On your local development host initialise the git repository in your project’s directory: git init
  6. Add your remote hosting repository: git remote add origin git@gitorious.org:my-project-name/my-git-repo.git
  7. Add your project files: git add .
  8. Do your initial commit: git commit -m "Initial commit"
  9. Push your project to the Gitorious repository: git push origin master

capistrano deployment fails after dreamhost server move

Problem
You have set up your capistrano recipe for deployment to dreamhost using password less logins, but after dreamhost moves your git repository server to a different server, the deployment breaks, with ‘permission denied’ when trying to get the git repository.

Solution
As the server was moved you would need to copy your ssh public key from the deployment server to the new server again for the password-less logins to work again.
Follow the details here how to copy your public key across, login in once with your password, and after that your capistrano recipe should be working again as normal.

git and dreamhost : refusing to update checked out branch: refs/heads/master

Problem
After dreamhost decided to move my account that hosted the git repository to a new server, first time I’ve tried to push some changes to the git repository I was faced with the followng error:

Counting objects: 13, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 699 bytes, done.
Total 7 (delta 6), reused 0 (delta 0)
error: refusing to update checked out branch: refs/heads/master
error: By default, updating the current branch in a non-bare repository
error: is denied, because it will make the index and work tree inconsistent
error: with what you pushed, and will require 'git reset --hard' to match
error: the work tree to HEAD.
error:
error: You can set 'receive.denyCurrentBranch' configuration variable to
error: 'ignore' or 'warn' in the remote repository to allow pushing into
error: its current branch; however, this is not recommended unless you
error: arranged to update its work tree to match what you pushed in some
error: other way.
error:
error: To squelch this message and still keep the default behaviour, set
error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To ssh://dh_user@dh_domain/home/repository_path/projects/project.git

Solution
After searching and finding out various solutions to solve the problem, none of which was specific to a server move, I’ve tried the following:

  • Followed the steps here to set up a new repository project_asm.git
  • went to local project changed the config file to add the new remote repository
  • issued git push new_remote master
  • make a code change and then git push

And everything should work as normal again.