Skip to content

Commit d2594b2

Browse files
author
lu0
committed
Add initial README
1 parent 6b11dc9 commit d2594b2

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# git-worktree-wrapper
2+
3+
Wrapper script to easily execute common git-worktree commands.
4+
5+
This script works kind of like a pre hook for checkout/switch/branch to
6+
create, switch and delete worktrees by using only widely known commands.
7+
8+
9+
## Installation
10+
11+
Clone this repository, try with a bare clone!
12+
13+
```sh
14+
git clone --bare https://github.com/lu0/git-worktree-wrapper
15+
cd git-worktree-wrapper.git
16+
git worktree add master && cd master
17+
```
18+
19+
Add the `git-wrapper-script` to your local `PATH`
20+
21+
```sh
22+
ln -srf git-worktree-wrapper.sh ~/.local/bin/git-worktree-wrapper
23+
```
24+
25+
Install [my modified fork of
26+
complete_alias](https://github.com/lu0/complete-alias).
27+
28+
```sh
29+
sudo apt install bash-completion
30+
git clone https://github.com/lu0/complete-alias
31+
echo ". $PWD/complete_alias" >> ~/.bash_completion
32+
```
33+
34+
Inherit `git`'s completion rules by pasting the following in your `~/.bashrc` or
35+
`~/.bash_aliases`
36+
37+
```sh
38+
alias git="source git-worktree-wrapper"
39+
complete -F _complete_alias git
40+
_complete_alias_overrides() {
41+
echo git git
42+
}
43+
```
44+
45+
## Usage
46+
47+
### Prerequisites
48+
49+
Set the `EDITOR` environment variable in your `~/.bashrc`. The script will try
50+
to open worktrees using this editor. Set `NO_GIT_WORKTREE_EDITOR=1` to handle
51+
your editor workspaces manually.
52+
53+
```sh
54+
# Example using vscode
55+
export EDITOR=code
56+
```
57+
58+
### Create a new worktree
59+
60+
This will also create a new branch.
61+
62+
```sh
63+
git checkout [-b|-B] another_branch
64+
```
65+
66+
### Open an existing worktree
67+
68+
This can be executed even if the current directory is the root of the bare
69+
repository.
70+
71+
```sh
72+
git checkout master
73+
```
74+
75+
### Delete a worktree
76+
77+
This will also delete the branch.
78+
79+
```sh
80+
git branch [-d|-D] another_branch
81+
```

0 commit comments

Comments
 (0)