diff --git a/app/controllers/graph_controller.rb b/app/controllers/graph_controller.rb
index b4bf956511295a2bccd8460fc746d8711690da29..c79ed5ca3cc095f3ace80ebfdee2ecdb3506b1e9 100644
--- a/app/controllers/graph_controller.rb
+++ b/app/controllers/graph_controller.rb
@@ -8,21 +8,15 @@ class GraphController < ProjectResourceController
   before_filter :require_non_empty_project
 
   def show
-    if params.has_key?(:q)
-      if params[:q].blank?
-        redirect_to project_graph_path(@project, params[:id])
-        return
-      end
-
-      @q = params[:q]
-      @commit = @project.repository.commit(@q) || @commit
+    if @options[:q]
+      @commit = @project.repository.commit(@options[:q]) || @commit
     end
 
     respond_to do |format|
       format.html
 
       format.json do
-        @graph = Network::Graph.new(project, @ref, @commit)
+        @graph = Network::Graph.new(project, @ref, @commit, @options[:filter_ref])
       end
     end
   end
diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb
index 188feb73ec1a053f87456092f2d0648576562526..e7def3984f89c9d52c952dc3b61a40cdaf39450d 100644
--- a/app/controllers/refs_controller.rb
+++ b/app/controllers/refs_controller.rb
@@ -1,24 +1,22 @@
 class RefsController < ProjectResourceController
+  include ExtractsPath
 
   # Authorize
   before_filter :authorize_read_project!
   before_filter :authorize_code_access!
   before_filter :require_non_empty_project
 
-  before_filter :ref
-  before_filter :define_tree_vars, only: [:blob, :logs_tree]
-
   def switch
     respond_to do |format|
       format.html do
         new_path = if params[:destination] == "tree"
-                     project_tree_path(@project, (@ref + "/" + params[:path]))
+                     project_tree_path(@project, (@id))
                    elsif params[:destination] == "blob"
-                     project_blob_path(@project, (@ref + "/" + params[:path]))
+                     project_blob_path(@project, (@id))
                    elsif params[:destination] == "graph"
-                     project_graph_path(@project, @ref)
+                     project_graph_path(@project, @id, @options)
                    else
-                     project_commits_path(@project, @ref)
+                     project_commits_path(@project, @id)
                    end
 
         redirect_to new_path
@@ -42,27 +40,4 @@ class RefsController < ProjectResourceController
       }
     end
   end
-
-  protected
-
-  def define_tree_vars
-    params[:path] = nil if params[:path].blank?
-
-    @repo = project.repository
-    @commit = @repo.commit(@ref)
-    @tree = Tree.new(@repo, @commit.id, @ref, params[:path])
-    @hex_path = Digest::SHA1.hexdigest(params[:path] || "")
-
-    if params[:path]
-      @logs_path = logs_file_project_ref_path(@project, @ref, params[:path])
-    else
-      @logs_path = logs_tree_project_ref_path(@project, @ref)
-    end
-  rescue
-    return render_404
-  end
-
-  def ref
-    @ref = params[:id] || params[:ref]
-  end
 end
diff --git a/app/controllers/tree_controller.rb b/app/controllers/tree_controller.rb
index a03ea3ff30d6ec30d65d0290cef99c8c7c07d18f..24e1329f926ad710be51725728f3a3f5099661c6 100644
--- a/app/controllers/tree_controller.rb
+++ b/app/controllers/tree_controller.rb
@@ -8,9 +8,6 @@ class TreeController < ProjectResourceController
   before_filter :require_non_empty_project
 
   def show
-    @hex_path  = Digest::SHA1.hexdigest(@path)
-    @logs_path = logs_file_project_ref_path(@project, @ref, @path)
-
     respond_to do |format|
       format.html
       # Disable cache so browser history works
diff --git a/app/models/network/graph.rb b/app/models/network/graph.rb
index 27072836cbb7b673949f2a8da87216c937f57291..ffec4712e457714f7758b73bec3b97dc69849b2b 100644
--- a/app/models/network/graph.rb
+++ b/app/models/network/graph.rb
@@ -8,10 +8,11 @@ module Network
       @max_count ||= 650
     end
 
-    def initialize project, ref, commit
+    def initialize project, ref, commit, filter_ref
       @project = project
       @ref = ref
       @commit = commit
+      @filter_ref = filter_ref
       @repo = project.repo
 
       @commits = collect_commits
@@ -107,7 +108,9 @@ module Network
         skip: skip
       }
 
-      Grit::Commit.find_all(@repo, nil, opts)
+      ref = @ref if @filter_ref
+
+      Grit::Commit.find_all(@repo, ref, opts)
     end
 
     def commits_sort_by_ref
diff --git a/app/views/graph/_head.html.haml b/app/views/graph/_head.html.haml
index fba9a958a191426605884fb2a9dbf834e43382dd..7a5b3c6f43d5799e5da165093f371069af6c4805 100644
--- a/app/views/graph/_head.html.haml
+++ b/app/views/graph/_head.html.haml
@@ -3,14 +3,24 @@
 
 .clearfix
   .pull-left
-    = render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path}
+    = render partial: 'shared/ref_switcher', locals: {destination: 'graph'}
+  .pull-left
+    = form_tag project_graph_path(@project, @id), method: :get do |f|
+      .control-group
+        = label_tag :filter_ref, "Show only selected ref", class: 'control-label light'
+        .controls
+          = check_box_tag :filter_ref, 1, @options[:filter_ref]
+    - @options.each do |key, value|
+      = hidden_field_tag(key, value, id: nil) unless key == "filter_ref"
 
   .search.pull-right
-    = form_tag project_graph_path(@project, params[:id]), method: :get do |f|
+    = form_tag project_graph_path(@project, @id), method: :get do |f|
       .control-group
         = label_tag :search , "Looking for commit:", class: 'control-label light'
         .controls
-          = text_field_tag :q, @q, placeholder: "Input SHA", class: "search-input xlarge"
+          = text_field_tag :q, @options[:q], placeholder: "Input SHA", class: "search-input xlarge"
           = button_tag type: 'submit', class: 'btn vtop' do
             %i.icon-search
+          - @options.each do |key, value|
+            = hidden_field_tag(key, value, id: nil) unless key == "q"
 
diff --git a/app/views/graph/show.html.haml b/app/views/graph/show.html.haml
index 682d27989062bbf4bd5a03cd7c59391d05187430..0ee6648317cc536aa5ff973e2cce5f5d107b2883 100644
--- a/app/views/graph/show.html.haml
+++ b/app/views/graph/show.html.haml
@@ -7,9 +7,11 @@
 
 :javascript
   var branch_graph;
-
+  $("#filter_ref").click(function() {
+    $(this).closest('form').submit();
+  });
   branch_graph = new BranchGraph($("#holder"), {
-    url: '#{project_graph_path(@project, @ref, q: @q, format: :json)}',
+    url: '#{project_graph_path(@project, @ref, @options.merge(format: :json))}',
     commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}',
     ref: '#{@ref}',
     commit_id: '#{@commit.id}'
diff --git a/app/views/shared/_ref_switcher.html.haml b/app/views/shared/_ref_switcher.html.haml
index 8b44cf1944ee91793130cb8769c722c9090391e6..dc8c656e12e571b9024c572c377623dcaa982ca1 100644
--- a/app/views/shared/_ref_switcher.html.haml
+++ b/app/views/shared/_ref_switcher.html.haml
@@ -3,3 +3,5 @@
   = hidden_field_tag :destination, destination
   - if defined?(path)
     = hidden_field_tag :path, path
+  - @options && @options.each do |key, value|
+    = hidden_field_tag key, value, id: nil
diff --git a/features/project/network.feature b/features/project/network.feature
index 538124a4c5f7cfe0c8ab7cec199b060c49a97eaf..f98e19b60d322822ffe60e43ea35f78ad6ccd5b1 100644
--- a/features/project/network.feature
+++ b/features/project/network.feature
@@ -25,3 +25,12 @@ Feature: Project Network Graph
     Then page should have network graph
     And page should select "master" in select box
     And page should have "v2.1.0" on graph
+
+  @javascript
+  Scenario: I should filter selected tag
+    When I switch ref to "v2.1.0"
+    Then page should have content not cotaining "v2.1.0"
+    When click "Show only selected branch" checkbox
+    Then page should not have content not cotaining "v2.1.0"
+    When click "Show only selected branch" checkbox
+    Then page should have content not cotaining "v2.1.0"
diff --git a/features/steps/project/project_network_graph.rb b/features/steps/project/project_network_graph.rb
index 8db6a39e99fa5c10502749b9f6a2c1ac6325c009..48a73f09face8c48b69be810673510edb3588ef5 100644
--- a/features/steps/project/project_network_graph.rb
+++ b/features/steps/project/project_network_graph.rb
@@ -19,6 +19,10 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
     page.should have_selector '#ref_chzn span', text: "master"
   end
 
+  And 'page should select "v2.1.0" in select box' do
+    page.should have_selector '#ref_chzn span', text: "v2.1.0"
+  end
+
   And 'page should have "master" on graph' do
     within '.graph' do
       page.should have_content 'master'
@@ -35,6 +39,28 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
     sleep 2
   end
 
+  When 'I switch ref to "v2.1.0"' do
+    page.select 'v2.1.0', from: 'ref'
+    sleep 2
+  end
+
+  When 'click "Show only selected branch" checkbox' do
+    find('#filter_ref').click
+    sleep 2
+  end
+
+  Then 'page should have content not cotaining "v2.1.0"' do
+    within '.graph' do
+      page.should have_content 'cleaning'
+    end
+  end
+
+  Then 'page should not have content not cotaining "v2.1.0"' do
+    within '.graph' do
+      page.should_not have_content 'cleaning'
+    end
+  end
+
   And 'page should select "stable" in select box' do
     page.should have_selector '#ref_chzn span', text: "stable"
   end
diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb
index 1b7c698d0a87acd28d59cddd04b32d2e4d4110a2..a81c80cfc6f2cd62f26a055b00ca4b0c62720dd4 100644
--- a/lib/extracts_path.rb
+++ b/lib/extracts_path.rb
@@ -94,16 +94,33 @@ module ExtractsPath
   # Automatically renders `not_found!` if a valid tree path could not be
   # resolved (e.g., when a user inserts an invalid path or ref).
   def assign_ref_vars
-    @id = params[:id]
+    @id = get_id
 
     @ref, @path = extract_ref(@id)
 
-    @commit = @project.repository.commit(@ref)
+    @repo = @project.repository
 
-    @tree = Tree.new(@project.repository, @commit.id, @ref, @path)
+    @commit = @repo.commit(@ref)
+
+    @tree = Tree.new(@repo, @commit.id, @ref, @path)
+    @hex_path = Digest::SHA1.hexdigest(@path)
+    @logs_path = logs_file_project_ref_path(@project, @ref, @path)
+
+    # assign allowed options
+    allowed_options = ["filter_ref", "q"]
+    @options = params.select {|key, value| allowed_options.include?(key) && !value.blank? }
+    @options = HashWithIndifferentAccess.new(@options)
 
     raise InvalidPathError unless @tree.exists?
   rescue RuntimeError, NoMethodError, InvalidPathError
     not_found!
   end
+
+  private
+
+  def get_id
+    id = params[:id] || params[:ref]
+    id += "/" + params[:path] unless params[:path].blank?
+    id
+  end
 end