git clone & pull without changing directories
If you’re trying to configure git commands in a directory that isn’t pwd, you’ll have to deal with clone and pull a little differently. Clone works like this:
1 git clone [source location] [destination location]
An example clone into my application’s vendor directory:
1 git clone git://github.com/rails/rails.git ~/rails/myapp/vendor/rails
Pull works like this:
1 git --git-dir=/path/to/destination/.git pull
An example pull in the already initiated local rails repository:
1 git --git-dir=~/rails/myapp/vendor/rails/.git pull
Using these approaches, you can simplify your capistrano recipes. here is an example snippet:
1 set :rails_source, "git://github.com/rails/rails.git" 2 3 desc "git the latest rails" 4 task :git_rails do 5 run "mkdir -p #{shared_path}/vendor" 6 result = run_and_return "ls #{shared_path}/vendor" 7 if result.match(/rails/) 8 run "git --git-dir=#{shared_path}/vendor/rails/.git pull" 9 else 10 run "git clone #{rails_source} #{shared_path}/vendor/rails" 11 end 12 end
See man git-clone and man git-pull for more details.
