My ~/git/ directory as a repository.
Tip
You can use mise to install all of these requirements. After cloning, just run:
mise trust
mise install- Clone the repository to
~/git(or wherever you put yourgit/directory).- HTTP:
git clone https://github.com/redjax/git_dir.git ~/git - SSH:
git clone [email protected]:redjax/git_dir ~/git
- HTTP:
- Trust the
.mise.tomlfile and install all tools.mise trust && mise install
- Optionally, copy the commented example
.envrc.localsection at the bottom of the.envrcand paste it into a new file at~/git/.envrc.local.- You can set local overrides or machine-specific environment variables.
- Trust the file with
direnv allow. - Now, any time you
cdinto the~/gitdirectory,direnvwill source those files and set the environment variables you define. - When you
cdout of the~/gitdirectory,direnvwill handle unloading those variables.
- Run
task -lto list allgo-task/tasksessions (to ensuretaskcommands will work).
Now you can start cloning repositories into the repos/ directory. For example, git clone [email protected]/username/repository.git repos/local_repo_name. That repository can now be managed by the tasks, automations, etc in this ~/git repository.
After cloning a repository, test running the status-all task:
task status-allClone this repository:
## HTTP
git clone https://github.com/redjax/git_dir.git ~/git
## SSH
git clone [email protected]:redjax/git_dir.git ~/gitcd into ~/git and run:
## Trust & install tools with mise
mise trust && mise install
## Enable direnv
direnv allow
## List tasks ensure go-task/task is working
task -lIf you open a repo from the repos/ directory in VSCode, the source control plugin might default to the ~/git repository. To fix this, open VSCode's settings (CTRL+,) and search for git auto repository detection. Look for this option:
Git: Auto Repository Detection
Configures when repositories should be automatically detected.
And set the dropdown to false, then reload your window.
When you clone repositories, put them in the repos/ directory. You can use whatever structure you want, i.e. clone every repo right into repos/, or put them in subdirectories. However you want to organize your repositories, just make sure they are all under the ~/git/repos/ path.
This structure accomplishes a few things:
- Fully isolates the repositories from the
~/gitmeta-repository. - Allows for easily targeting only your cloned repos, and not the
~/gitrepository itself, i.e. for scans or scripts. - Keeps VSCode decluttered.
- If you open the
~/gitrepository in VSCode, the source-control plugin will be overwhelmed by all of the repositories if they are all in the root of~/git. - Nesting repositories in the
repos/directory allows you to open the~/gitrepository in its own, isolated workspace.
- If you open the
Note
There are a couple of exceptions to this. You can store sparse clones in the sparse-clones/ directory, and git worktrees in the worktrees/ directory.
In general, unless you have a reason to keep a git repository in another path in the ~/git directory, use the repos/ directory to clone/create new repositories.
You can use direnv to automatically set environment variables when you cd into the ~/git repository, and un-set them automatically when you cd out of that directory.
The .envrc file sets some environment variables that will be the same across every machine that clones this repository. It is source-controlled, and should remain generic, and free of any secret/personal data.
If you want to add more custom environment variables for the specific machine you're working on, you can create a .envrc.local file, which will be ignored by git so you can put whatever environment variables you want in it. Just copy the commented code at the bottom of the .envrc file to .envrc.local, delete the # at the beginning of each line, and customize to your liking.
You can set whatever environment variables you want in this file. Think of it a bit like a ~/.bashrc, but only while your shell session's working directory is ~/git.
If you navigate to another directory, i.e. cd ../ or cd repos/, the environment variables will unload.
You can use go-task/task, which reads from the Taskfile.yml to create cross-platform sessions. Inspired by Make, go-task/task is primarily a build tool, but can be used for all kinds of automations.
The Taskfile.yml imports tasks defined in the .tasks/ directory. You can list all available tasks with:
$ task -l
task: Available tasks for this project:
* default: Show machine info
* fetch-all: Synchronize all git directories in the current path
* status-all: Show `git status` for all repos found in current path
* git:fetch-all: Fetch --all --prune for all repositories (parallel, worktree only)
* git:status-all: Show dirty git status for all repositoriesRunning a task is as simple as running task <task-name>. For example, to check the status of all repositories found in ~/git/{repos,sparse-clones,worktrees}:
task status-all