diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go
index ae9f04b113..df575f30c0 100644
--- a/modules/middleware/repo.go
+++ b/modules/middleware/repo.go
@@ -160,7 +160,7 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
 		}
 
 		ctx.Data["BranchName"] = ctx.Repo.BranchName
-		ctx.Data["Branches"], _ = models.GetBranches(ctx.User.Name, ctx.Repo.Repository.Name)
+		ctx.Data["Branches"], _ = models.GetBranches(user.Name, repoName)
 		ctx.Data["CommitId"] = ctx.Repo.CommitId
 		ctx.Data["IsRepositoryWatching"] = ctx.Repo.IsWatching
 	}