You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If your company has a large number of repositories and your work involves jumping between a lot of them then git-workspace can save you some time by:
Easily synchronizing your projects directory with Github, Gitlab.com, Gitlab self-hosted or Gitea
Keep projects consistently named and under the correct path
Automatically set upstreams for forks
Move deleted repositories to an archive directory
Allowing you to access any repository instantly
Execute git fetch on all projects in parallel
This may sound useless, but the "log into your git provider, browse to the project, copy the clone URL, devise a suitable path to clone it" dance can be a big slowdown. The only obvious solution here is to spend more time than you'll ever spend doing this in your whole life on writing a tool in Rust to do it for you.
SUBCOMMANDS: add Add a provider to the configuration archive Archive repositories that don't exist in the workspace anymore fetch Fetch new commits for all repositories in the workspace help Prints this message or the help of the given subcommand(s) list List all repositories in the workspace lock Fetch all repositories from configured providers and write the lockfile run Run a git command in all repositories switch-and-pull Pull new commits on the primary branch for all repositories in the workspace update Update the workspace, removing and adding any repositories as needed
Define your workspace
A workspace is the directory that git-workspace will manage for you, filling it with projects cloned from your providers. To configure this just set a GIT_WORKSPACE environment variable that points to an empty directory. For example:
export GIT_WORKSPACE=~/projects
Provider credentials
Both Github and Gitlab require personal access tokens to access their GraphQL endpoints. Create an access token here:
Git workspace will read from any workspace*.toml file under your $GIT_WORKSPACE directory.
Updating your workspace
Running git workspace update will:
Fetch all repositories from your providers
Clone any new repositories that are not present locally
Move any deleted repositories to $GIT_WORKSPACE/.archived/ for posterity
Fetching all changes
git workspace fetch will run git fetch on all projects.
Switch projects
git workspace list will output the names of all your projects. You can integrate this with whatever tool you wish to provide a way to quickly search for and select repositories.
The following fish shell snippet gives you a open-project [search-string] command you can use to search for and open projects. It combines the git workspace list command with fzf, and opens the project path with your $EDITOR:
# ~/.config/fish/functions/open-project.fish functionopen-project -d"Open a project" set filter "$argv" set chosen_project (git workspace list | fzf -q"$filter") if string length -q -- $chosen_project $EDITOR$GIT_WORKSPACE/$chosen_project pushd$GIT_WORKSPACE/$chosen_project end end
function project { local filter="$@" local chosen_project=$(git workspace list | fzf -q "$filter") if [[ -n $chosen_project ]]; then pushd "$GIT_WORKSPACE/$chosen_project" fi }
#!/bin/sh # shellcheck shell=sh # Written to comply with IEEE Std 1003.1-2017 for standard POSIX environment
###! # WorkSPace (wsp) ###! Switches to specified git-workspace project directory ###! - Requires git and fzf wsp() { # Check for required non-standard commands forcommandin${FZF:-"fzf"}${GIT:-"git"};do ${COMMAND:-"command"} -v "$command"|| { ${PRINTF:-"printf"}"FATAL: %s\\n""Command '$command' is not executable";${EXIT:-"exit"} 127 ;} done
# shellcheck disable=SC2086 # Harmless warning about missing double-quotes that are not expected to allow parsing multiple arguments wsp_path="${1:-"${GTT_WORKSPACE:-"$PWD"}/$(${GIT:-"git"} workspace list |${FZF:-"fzf"}${fzf_arg:-"-q"}"$@")"}"# Path to the git workspace directory
# Change directory ${CD:-"cd"}"$wsp_path"|| { printf"FATAL: %s\\n""Unable to change directory to '$wsp_path'";} }
This is my first 'proper' Rust project. If you're experienced with Rust you might puke at the code, but any feedback to help me improve would be greatly appreciated!
If you want to contribute then just go for it. cargo install should get you ready to go. Be warned: there are currently no tests . I run integration tests with Github Actions, but that's about it. It's on my to-do list, I promise (tm).
About
Sync personal and work git repositories from multiple providers