diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb
index 0bba019918f69730f8ea37dc5797493281f9c6e8..1e523050ff218d834f8be3afc1f5dda826f2d4ac 100644
--- a/app/controllers/admin/groups_controller.rb
+++ b/app/controllers/admin/groups_controller.rb
@@ -48,14 +48,18 @@ class Admin::GroupsController < AdminController
 
   def project_update
     project_ids = params[:project_ids]
-    Project.where(id: project_ids).update_all(group_id: @group.id)
+
+    Project.where(id: project_ids).each do |project|
+      project.namespace_id = @group.id
+      project.save
+    end
 
     redirect_to :back, notice: 'Group was successfully updated.'
   end
 
   def remove_project
     @project = Project.find(params[:project_id])
-    @project.group_id = nil
+    @project.namespace_id = nil
     @project.save
 
     redirect_to :back, notice: 'Group was successfully updated.'
diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb
index 8d9329f2b32e0f5d03c31fbe59da544c69d6e105..ad242d30f7fd34b4242a7d3abc557eeacfae07aa 100644
--- a/app/controllers/dashboard_controller.rb
+++ b/app/controllers/dashboard_controller.rb
@@ -4,7 +4,7 @@ class DashboardController < ApplicationController
   before_filter :event_filter, only: :index
 
   def index
-    @groups = Group.where(id: current_user.projects.pluck(:group_id))
+    @groups = Group.where(id: current_user.projects.pluck(:namespace_id))
     @projects = current_user.projects_sorted_by_activity
     @projects = @projects.page(params[:page]).per(30)
 
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index 63f70cd00275dc9b57f072ade08b2055378cc545..c98332eb984ba11af667be15e167f4652b9c0a17 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -54,7 +54,7 @@ class GroupsController < ApplicationController
   end
 
   def projects
-    @projects ||= current_user.projects_sorted_by_activity.where(group_id: @group.id)
+    @projects ||= current_user.projects_sorted_by_activity.where(namespace_id: @group.id)
   end
 
   def project_ids
diff --git a/app/observers/issue_observer.rb b/app/observers/issue_observer.rb
index 62fd9bf8ac937b31e5c3ce29fb3efd3c98243304..9f9762aea078be6802cf74248e99254693abc5ea 100644
--- a/app/observers/issue_observer.rb
+++ b/app/observers/issue_observer.rb
@@ -3,7 +3,7 @@ class IssueObserver < ActiveRecord::Observer
 
   def after_create(issue)
     if issue.assignee && issue.assignee != current_user
-      Notify.new_issue_email(issue.id).deliver 
+      Notify.new_issue_email(issue.id).deliver
     end
   end
 
@@ -14,8 +14,8 @@ class IssueObserver < ActiveRecord::Observer
     status = 'closed' if issue.is_being_closed?
     status = 'reopened' if issue.is_being_reopened?
     if status
-      Note.create_status_change_note(issue, current_user, status) 
-      [issue.author, issue.assignee].compact.each do |recipient| 
+      Note.create_status_change_note(issue, current_user, status)
+      [issue.author, issue.assignee].compact.each do |recipient|
         Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user)
       end
     end
diff --git a/app/observers/project_observer.rb b/app/observers/project_observer.rb
index 03a617098299c22ddcbaa97374ff4b13ae696fe9..18874e722746aaadf34fe494c30a420525affa18 100644
--- a/app/observers/project_observer.rb
+++ b/app/observers/project_observer.rb
@@ -1,6 +1,11 @@
 class ProjectObserver < ActiveRecord::Observer
   def after_save(project)
     project.update_repository
+
+    # Move repository if namespace changed
+    if project.namespace_id_changed?
+      move_project(project)
+    end
   end
 
   def after_destroy(project)
@@ -18,4 +23,19 @@ class ProjectObserver < ActiveRecord::Observer
   def log_info message
     Gitlab::AppLogger.info message
   end
+
+  def move_project(project)
+    old_dir = Namespace.find_by_id(project.namespace_id_was).try(:code) || ''
+    new_dir = Namespace.find_by_id(project.namespace_id).try(:code) || ''
+
+    # Create new dir if missing
+    new_dir_path = File.join(Gitlab.config.git_base_path, new_dir)
+    Dir.mkdir(new_dir_path) unless File.exists?(new_dir_path)
+
+    old_path = File.join(Gitlab.config.git_base_path, old_dir, "#{project.path}.git")
+    new_path = File.join(new_dir_path, "#{project.path}.git")
+
+    binding.pry
+    `mv #{old_path} #{new_path}`
+  end
 end
diff --git a/app/roles/repository.rb b/app/roles/repository.rb
index 884681178227f78e6e93d7a565cfd9911f0fc697..e49761b696c93228fc8a96ba7295b1116679610a 100644
--- a/app/roles/repository.rb
+++ b/app/roles/repository.rb
@@ -79,11 +79,15 @@ module Repository
   end
 
   def url_to_repo
-    git_host.url_to_repo(path)
+    git_host.url_to_repo(path_with_namespace)
   end
 
   def path_to_repo
-    File.join(Gitlab.config.git_base_path, "#{path}.git")
+    File.join(Gitlab.config.git_base_path, namespace_dir, "#{path}.git")
+  end
+
+  def namespace_dir
+    namespace.try(:code) || ''
   end
 
   def update_repository
diff --git a/spec/factories.rb b/spec/factories.rb
index 7c33f0ecc8b546ec7c4b48d8520fb8e9790dcba6..a49cd69ec699033ac9cb857f4deaf1b4a50647ba 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -29,10 +29,14 @@ FactoryGirl.define do
     owner
   end
 
-  factory :group do
+  factory :namespace do
     sequence(:name) { |n| "group#{n}" }
     code { name.downcase.gsub(/\s/, '_') }
     owner
+
+    factory :group do
+      type 'Group'
+    end
   end
 
   factory :users_project do
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
new file mode 100644
index 0000000000000000000000000000000000000000..ce97d01a116b2e00cf6958072a9e5dbf19d0d89c
--- /dev/null
+++ b/spec/models/namespace_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe Namespace do
+  let!(:namespace) { create(:namespace) }
+
+  it { should have_many :projects }
+  it { should validate_presence_of :name }
+  it { should validate_uniqueness_of(:name) }
+  it { should validate_presence_of :code }
+  it { should validate_uniqueness_of(:code) }
+  it { should validate_presence_of :owner }
+end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 5bcab924496051bfd01f2344c798d163f0f03404..dda9eefaa45bccda74825b43496ce48fc81ae4db 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -24,6 +24,7 @@ require 'spec_helper'
 describe Project do
   describe "Associations" do
     it { should belong_to(:group) }
+    it { should belong_to(:namespace) }
     it { should belong_to(:owner).class_name('User') }
     it { should have_many(:users) }
     it { should have_many(:events).dependent(:destroy) }