用ruby-git切换git分支不会切换文件?

Switching git branch with ruby-git does not switch the files?

我正在克隆一个有多个分支的 Github 存储库,例如:

root_dir    = Dir.mktmpdir(nil, Rails.root.join("repos").to_s)
root_folder = "ruby_git"
Git.clone("https://github.com/ruby-git/ruby-git.git", root_folder, :path => root_dir)

然后我尝试将分支切换到 "test":

g = Git.open(full_dir)
if g.current_branch != "test"
  puts g.branch("test").checkout # => "Switched to branch 'test'"
end

分支开关确认。我什至测试自己分支是否正确:

puts g.current_branch # => "test"

但是当我最终像这样检查文件时:

puts Dir["#{full_dir}/tests/*"] # => Wrong files that belongs to the default branch...

我看到该文件夹​​中仍然包含默认分支的文件,而不是我切换到的分支。

我做错了什么,我该如何解决?

自己找到了答案。

我需要拉我切换到的分支:

g.pull("origin", "test")

pull方法被引用here.