Code Monkey home page Code Monkey logo

gwt's Introduction

GPLv2 License

gwt - a Git worktree wrapper

gwt is a Bash function to make working with git worktree a little easier. It provides functionality for listing all existing worktrees, creating new worktrees, removing stale worktrees, and automates updating a worktree upon entering it.

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

GWT_REPO_HOME

Usage/Examples

Set up / Configuration

  1. Tell gwt where your Git repos live
~ $ export GWT_REPO_HOME=/srv/repos
  1. Load gwt into your current shell
~ $ source /path/to/gwt

Usage

List all worktrees in all repositories

~ $ gwt
/srv/repos/demo
↳ ask_me_about_free_upgrades                       48f9fefb8 [ask_me_about_free_upgrades]
↳ because_it_zee_standard                          08885f5f8 [because_it_zee_standard]
↳ bye_bye_ssh_hello_tls                            96e7caa91 [bye_bye_ssh_hello_tls]
↳ clusters_have_names                              47441094e [clusters_have_names]
↳ compute_pg_defaults                              f17eb3306 [compute_pg_defaults]
↳ computed_processes                               b2b0f4b75 [computed_processes]
↳ development                                      05f001eee [development]
↳ etcd_api_v3                                      fb0c287e3 [etcd_api_v3]
↳ heap-2660                                        67ed98aa9 [heap-2660]
↳ heap-2661                                        0b00da61f [heap-2661]
↳ ini_mini_miti_mo                                 1317ffaa1 [ini_mini_miti_mo]
↳ int_int_baby                                     4b38207c0 [int_int_baby]
↳ lint_lint_baby                                   ae72361e5 [lint_lint_baby]
↳ make_fetch_happen_for_gretchen                   bb74fe721 [make_fetch_happen_for_gretchen]
↳ pls_get_fresh_with_me                            4f2b6579f [pls_get_fresh_with_me]
↳ prepare_this                                     9d011fd4e [prepare_this]
↳ raft_beta                                        6ac90e7a0 [raft_beta]
↳ repov2                                           5020895e3 [repov2]
↳ rhel_9                                           27c2c4cf6 [rhel_9]
↳ unlimited_cosmic_files__itty_bitty_living_space  257c64a34 [unlimited_cosmic_files__itty_bitty_living_space]
↳ use_the_modules_luke                             a3d0d96af [use_the_modules_luke]
↳ validate_patroni                                 bd13c04a6 [validate_patroni]
↳ what_does_inactive_even_mean                     fcdc9c36e [what_does_inactive_even_mean]
↳ what_is_a_default_anyway                         d9ef509b1 [what_is_a_default_anyway]
↳ wilson_and_me_on_a_raft                          6184f8da0 [wilson_and_me_on_a_raft]

/srv/repos/set_user
↳ v4_upgrade_note  6b385b2 [v4_upgrade_note]

/srv/repos/pgmonitor
↳ development  da0824c [development]

List all worktrees in a given repo

~ $ gwt ls demo
demo
↳ ask_me_about_free_upgrades                       48f9fefb8 [ask_me_about_free_upgrades]
↳ because_it_zee_standard                          08885f5f8 [because_it_zee_standard]
↳ bye_bye_ssh_hello_tls                            96e7caa91 [bye_bye_ssh_hello_tls]
↳ clusters_have_names                              47441094e [clusters_have_names]
↳ compute_pg_defaults                              f17eb3306 [compute_pg_defaults]
↳ computed_processes                               b2b0f4b75 [computed_processes]
↳ development                                      05f001eee [development]
↳ etcd_api_v3                                      fb0c287e3 [etcd_api_v3]
↳ heap-2660                                        67ed98aa9 [heap-2660]
↳ heap-2661                                        0b00da61f [heap-2661]
↳ ini_mini_miti_mo                                 1317ffaa1 [ini_mini_miti_mo]
↳ int_int_baby                                     4b38207c0 [int_int_baby]
↳ lint_lint_baby                                   ae72361e5 [lint_lint_baby]
↳ make_fetch_happen_for_gretchen                   bb74fe721 [make_fetch_happen_for_gretchen]
↳ pls_get_fresh_with_me                            4f2b6579f [pls_get_fresh_with_me]
↳ prepare_this                                     9d011fd4e [prepare_this]
↳ raft_beta                                        6ac90e7a0 [raft_beta]
↳ repov2                                           5020895e3 [repov2]
↳ rhel_9                                           27c2c4cf6 [rhel_9]
↳ unlimited_cosmic_files__itty_bitty_living_space  257c64a34 [unlimited_cosmic_files__itty_bitty_living_space]
↳ use_the_modules_luke                             a3d0d96af [use_the_modules_luke]
↳ validate_patroni                                 bd13c04a6 [validate_patroni]
↳ what_does_inactive_even_mean                     fcdc9c36e [what_does_inactive_even_mean]
↳ what_is_a_default_anyway                         d9ef509b1 [what_is_a_default_anyway]
↳ wilson_and_me_on_a_raft                          6184f8da0 [wilson_and_me_on_a_raft]

Create a new worktree

~ $ gwt create demo demo
gwt: Checking if upstream is a fetchable remote
gwt: Fetching remote: upstream
gwt: Checking if development is a valid head on upstream remote
gwt: Creating worktree
Preparing worktree (new branch 'demo')
branch 'demo' set up to track 'upstream/development'.
HEAD is now at eec1595f1 update readme and contrib (#2056)
gwt: Checking if this repo uses submodules
gwt: No submodules configured in this repo
/srv/repos/demo/.trees/demo $

Switch to an existing worktree

~ $ gwt demo
gwt: Found the demo worktree
gwt: Checking if a merge is in progress
gwt: A merge IS NOT in progress
gwt: Determining the worktree's branch revision
gwt: Local worktree's branch revision: eec1595f1e2cc682e831678b47691ed2e13c835b
gwt: Fetching info from remote: origin
gwt: Checking if this branch exists on remote: origin
gwt: This worktree's branch not found on remote: origin
gwt: Determining the upstream remote for this branch
gwt: Determined the upstream remote for this branch: upstream
gwt: Determining the upstream branch for this branch
gwt: Determined the upstream branch for this branch: development
gwt: Fetching info from remote: upstream
gwt: Checking if upstream/development has advanced since last pull
gwt: Remote head has not advanced
/srv/repos/demo/.trees/demo $

Switch to a worktree where upstream has advanced

~ $ gwt heap-2660
gwt: Found the heap-2660 worktree
gwt: Checking if a merge is in progress
gwt: A merge IS NOT in progress
gwt: Determining the worktree's branch revision
gwt: Local worktree's branch revision: 67ed98aa9b2457d1ffede13545276fd7f0b57c1f
gwt: Fetching info from remote: origin
gwt: Checking if this branch exists on remote: origin
gwt: Checking the revision of this branch on: origin
gwt: Remote origin has this branch on revision: 67ed98aa9b2457d1ffede13545276fd7f0b57c1f
gwt: Checking the base revision of this branch on: origin
gwt: Revisions match; continuing
gwt: Determining the upstream remote for this branch
gwt: Determined the upstream remote for this branch: upstream
gwt: Determining the upstream branch for this branch
gwt: Determined the upstream branch for this branch: development
gwt: Fetching info from remote: upstream
gwt: Checking if upstream/development has advanced since last pull
gwt: Merging from remote head: upstream/development
/srv/repos/demo/.trees/heap-2660 $

Switch to a worktree with unpushed local commits

~ $ gwt heap-2660
gwt: Found the heap-2660 worktree
gwt: Checking if a merge is in progress
gwt: A merge IS NOT in progress
gwt: Determining the worktree's branch revision
gwt: Local worktree's branch revision: 36d59ff8d56a86e402a99f9c6ce3746c36643fd8
gwt: Fetching info from remote: origin
gwt: Checking if this branch exists on remote: origin
gwt: Checking the revision of this branch on: origin
gwt: Remote origin has this branch on revision: 67ed98aa9b2457d1ffede13545276fd7f0b57c1f
gwt: Checking the base revision of this branch on: origin
gwt: Pushing to remote: origin
gwt: Determining the upstream remote for this branch
gwt: Determined the upstream remote for this branch: upstream
gwt: Determining the upstream branch for this branch
gwt: Determined the upstream branch for this branch: development
gwt: Fetching info from remote: upstream
gwt: Checking if upstream/development has advanced since last pull
gwt: Merging from remote head: upstream/development
Already up to date.
/srv/repos/demo/.trees/heap-2660 $

Remove a worktree

~ $ gwt prune demo demo
gwt: Removing the worktree from disk: /srv/repos/demo/.trees/demo
gwt: Deleting the branch: demo
Deleted branch demo (was eec1595f1).
~ $

License

GPLv2

gwt's People

Contributors

hunleyd avatar tsykoduk avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

tsykoduk

gwt's Issues

clean up fake worktrees created by precommit

╭─doug@nuc ~  ‹main✔›
╰─➤  gwt
/srv/repos/priv-all-ansible-roles
↳ /home/doug/.cache/ansible-compat/875b93/old-rev                                           4b5e15fe0 (detached HEAD)
↳ /home/doug/.cache/ansible-compat/e805db/old-rev                                           013388bf3 (detached HEAD)

these should be deleted and git worktree prune run to get rid of them

check for local changes before trying to pull

# Update the index
git update-index -q --ignore-submodules --refresh
err=0

# Disallow unstaged changes in the working tree
if ! git diff-files --quiet --ignore-submodules --
then
    echo >&2 "cannot $1: you have unstaged changes."
    git diff-files --name-status -r --ignore-submodules -- >&2
    err=1
fi

# Disallow uncommitted changes in the index
if ! git diff-index --cached --quiet HEAD --ignore-submodules --
then
    echo >&2 "cannot $1: your index contains uncommitted changes."
    git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
    err=1
fi

Creating worktree from non devel branch fails

jchancojr@rubicon:~/Repos/priv-all-ansible-roles/.trees/something_something_darkside_pgconfig$ gwt create priv-all-ansible-roles 1_dot_14 upstream/v1_14-STABLE
gwt: Checking if upstream is a fetchable remote
gwt: Fetching remote: upstream
gwt: Checking if v1_14-STABLE is a valid head on upstream remote
gwt: Creating worktree
Preparing worktree (new branch '1_dot_14')
warning: refname 'upstream/v1_14-STABLE' is ambiguous.
fatal: ambiguous object name: 'upstream/v1_14-STABLE'

gwt: Creating the worktree FAILED !!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.