I use git worktree concept to create multiple working directory. One for each feature and/or bug fix. So I will create a git clone of a repository once, and then I start creating worktree as needed.
When I clone a git repository, by default a working directory is checked out - main worktree. Which we dont use and unnecessarily takes up space. So I am looking for a way to create a git repo with a working directory being checked out at the beginning.
I tried git clone --bare <url> ./test-git
which actually created a git repo without a working directory but I was not able to create a git worktree out of it. I use to throw the following error -
bash-4.4 [/user/darshan/test-git] $git worktree add -b test-git-worktree.repo ../test-git-worktree origin/repo
Preparing worktree (new branch 'test-git-worktree.repo')
fatal: Not a valid object name: 'origin/repo'.
- What am I doing wrong?
I went inside the .git
directory created from git clone bare
command and found that there was index
file and lfs
directory missing.
And these two items will be present in the .git
directory created from the full git clone.
- What do these two item indicate?
- On running what git command will I get these items?
We can create a git repository without a working copy using -
This just creates a directory (with repository name) with
.git
directory inside it.Note: Furthermore, I hope using git clone --bare should also provide similar functionality. But have not been able to figure that out yet.