Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use GTWS to manage Git workspaces

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use GTWS to manage Git workspace". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use GTWS to manage Git workspace".

Great Teeming Workspaces (GTWS) is a complex workspace management toolkit for Git that makes it easy for us to manage different projects and versions of projects in the development environment.

It's a bit like Python's venv, but not for the Python language. GTWS is used to manage multiple versions of workspaces for multiple projects. You can easily create, update, enter, and leave workspaces, and each combination of projects or versions (at most) has a local origin to synchronize with upstream-all remaining workspaces are updated from the local origin.

Deploy ${GTWS_ORIGIN} / / [/] ${GTWS_BASE_SRCDIR} / {[,...]}

Each level of the source code directory (including the global home directory) can contain a .gtwsrc file that maintains settings and bash code related to the current level. The configuration of each level will cover the upper level.

Installation

Check out the GTWS with the following command:

Git clone https://github.com/dang/gtws.git

Configure your ${HOME} / .gtwsrc. It should contain GTWS_ORIGIN, or it can also contain GTWS_SETPROMPT.

Add the warehouse catalog to the environment variable:

Export PATH= "${PATH}: / path/to/gtws configuration

Configure by cascading the .gtwsrc file. It traverses down from the root directory and executes the .gtwsrc file found in each level directory. The files in the lower directory will overwrite the previous level.

Make the following settings in your top file ~ / .gtws/.gtwsrc:

GTWS_BASE_SRCDIR: the base directory of all project source files directory trees. The default is $HOME/src.

GTWS_ORIGIN: specifies the path to the origin git directory tree. The default is $HOME/origin.

GTWS_SETPROMPT: optional configuration. If this parameter is configured, the shell prompt will have the name of the workspace.

GTWS_DEFAULT_PROJECT: does not specify the default project name when the project or the project is unknown. If not specified, the project must be specified when using the command line.

GTWS_DEFAULT_PROJECT_VERSION: the default version checked out. The default is master.

Make the following settings in the root directory of each project:

GTWS_PROJECT: name of the project (and base directory).

Gtws_project_clone: this function is used to clone a specified version of a project. If not defined, it assumes that the project's origin has a separate directory for each version, which results in cloning a stack of Git repositories.

Gtws_project_setup: after cloning all the repositories, you can choose whether or not to call this function, after which you can configure the project as necessary, such as configuring the workspace in IDE.

Make the following settings at the project version level:

GTWS_PROJECT_VERSION: version of the project. Used to pull code correctly from origin. Similar to the branch name in Git.

The following parameters can be configured anywhere in the directory tree, and if they take effect, they can be rewritten multiple times:

GTWS_PATH_EXTRA: these are the additional path elements added to the path in the workspace.

GTWS_FILES_EXTRA: these are additional files that are not under version control but should be checked out in the workspace. These files include .git / info/exclude, and each file is associated with the base directory of the repository.

Origin directory

GTWS_ORIGIN (in most scripts) points to the original Git check-out directory that was pulled and pushed.

${GTWS_ORIGIN} deployment:

/

This is the base directory of a project's warehouse.

If gtws_project_clone is specified, you can configure any deployment path.

If gtws_project_clone is not specified, there must be a subdirectory called git under this path, and there must be a series of naked Git repositories under the git directory for cloning.

Workflow exampl

Suppose you have a project called Foo and its upstream is github.com/foo/foo.git. The repository has a submodule called bar, and its upstream is github.com/bar/bar.git. The Foo project is developed in the master branch, using a stable version of the branch.

In order to use GTWS in Foo, you first need to configure the directory structure. In this example, it is assumed that you use the default directory structure.

Configure your top level .gtwsrc:

Cp ${GTWS_LOC} / examples/gtwsrc.top ~ / .gtwsrc

Modify ~ / .gtwsrc as needed.

Create a top-level directory:

Mkdir-p ~ / origin ~ / src

Create and configure the project directory:

Mkdir-p ~ / src/foo

Cp ${GTWS_LOC} / examples/gtwsrc.project ~ / src/foo/.gtwsrc

Modify ~ / src/foo/.gtwsrc as needed.

Create and configure the master version directory:

Mkdir-p ~ / src/foo/master

Cp ${GTWS_LOC} / examples/gtwsrc.version ~ / src/foo/master/.gtwsrc

Modify ~ / src/foo/master/.gtwsrc as needed.

Go to the version directory and create a temporary workspace to configure the image:

Mkdir-p ~ / src/foo/master/tmp

Cd ~ / src/foo/master/tmp

Git clone-recurse-submodules git://github.com/foo/foo.git

Cd foo

Gtws-mirror-o ~ / origin-p foo (translation note: there is an error in the original text, if you do not add the-s parameter, the error will be reported)

The above command creates ~ / origin/foo/git/foo.git and ~ / origin/foo/submodule/bar.git.

Future cloning operations will be cloned from these origin instead of upstream.

You can now delete the workspace.

By now, the work on the master branch of Foo can be done. Suppose you now want to fix a bug called bug1234. You can create a separate workspace from your current workspace to fix this bug, and then develop it in the newly created workspace.

Go to the version directory and create a new workspace:

Cd ~ / src/foo/master

Mkws bug1234

The above command creates bug1234/, checks out Foo (and its submodule bar) in this directory, and creates build/foo to build it.

There are two ways to enter the workspace:

Cd ~ / src/foo/master/bug1234

Startws

Or

Cd ~ / src/foo/master/

Startws bug1234

The above command opens a sub-shell in the bug1234 workspace. This shell has the GTWS environment and the environment you set up in the .gtwsrc file at all levels. It also adds the base directory of your workspace to CD, so you can cd from the base path to the relevant directory.

Now you can fix bug1234, build, test, and commit your changes. When you can push the code to upstream, execute the following command:

Cd foo

Wspush

Wspush will push the code to the branch that is relevant to your workspace-first to the local origin, then to upstream.

When upstream is modified, you can synchronize it locally with the following command:

Git sync

The above command invokes GTWS's git-sync script and updates the code from the local origin. Update the local origin using the following command:

Git sync-o

The above command will update the image of your local origin and submodules, and then use those commands to update your checkout repository code. Git-sync also has some other good work.

When you want to finish working in the workspace, exit shell directly:

Exit

You can re-enter the workspace at any time, or you can open multiple shell in the same workspace at the same time.

When you don't need a workspace, you can use rmws to delete it, or simply delete its directory tree.

There is also a script tmws that uses tmux to enter the workspace to create a series of windows / panes, which fits my workflow perfectly. You can modify it according to your own needs.

Thank you for your reading, the above is the content of "how to use GTWS to manage Git workspace". After the study of this article, I believe you have a deeper understanding of how to use GTWS to manage Git workspace, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report