git checkout branch without checking files


April 2019


43 time


I have huge size of git repo in my local system with 10 different branches, In those 10 branch the master repository is around 2 GB. when i switch from any branch1 to master branch, Git is trying to checkout all files in local system itself, how to reduce the time here.

  [[email protected]_001 myrepo]$ time git checkout master
   Checking out files: 100% (25765/25765), done.
   Switched to branch 'master'

   real    0m55.617s
   user    0m35.597s
   sys     0m5.002s

Here i have reduce 55 sec

1 answers


One workaround would be to use the git worktree command: you can clone a repo once, but check it out in multiple folders, one per branch.

That way, instead of changing your current worktree, you can simply change folder to the one where master is already checked out) and update its content with a git pull (incremental update, much faster)

That seems easier than trying to put in place a sparse checkout or a shallow clone.