gitbetter.git

  1import shlex
  2import subprocess
  3import sys
  4from contextlib import contextmanager
  5
  6
  7class Git:
  8    def __init__(self, capture_stdout: bool = False):
  9        """If `capture_stdout` is `True`, all functions will return their generated `stdout` as a string.
 10        Otherwise, the functions return the call's exit code."""
 11        self.capture_stdout = capture_stdout
 12
 13    @contextmanager
 14    def capture_output(self):
 15        self.capture_stdout = True
 16        yield self
 17        self.capture_stdout = False
 18
 19    @property
 20    def capture_stdout(self) -> bool:
 21        """If `True`, member functions will return the generated `stdout` as a string,
 22        otherwise they return the command's exit code."""
 23        return self._capture_stdout
 24
 25    @capture_stdout.setter
 26    def capture_stdout(self, should_capture: bool):
 27        self._capture_stdout = should_capture
 28
 29    def _run(self, args: list[str]) -> str | int:
 30        if self._capture_stdout:
 31            return subprocess.run(args, stdout=subprocess.PIPE, text=True).stdout
 32        else:
 33            return subprocess.run(args).returncode
 34
 35    def execute(self, command: str) -> str | int:
 36        """Execute git command.
 37
 38        Equivalent to executing `git {command}` in the shell."""
 39        args = ["git"] + shlex.split(command)
 40        return self._run(args)
 41
 42    def new_repo(self) -> str | int:
 43        """Executes `git init -b main`."""
 44        return self.execute("init -b main")
 45
 46    def loggy(self) -> str | int:
 47        """Equivalent to `git log --oneline --name-only --abbrev-commit --graph`."""
 48        return self.execute("log --oneline --name-only --abbrev-commit --graph")
 49
 50    def status(self) -> str | int:
 51        """Execute `git status`."""
 52        return self.execute("status")
 53
 54    # ======================================Staging/Committing======================================
 55    def commit(self, args: str) -> str | int:
 56        """>>> git commit {args}"""
 57        return self.execute(f"commit {args}")
 58
 59    def add(self, files: list[str] | None = None) -> str | int:
 60        """Stage a list of files.
 61
 62        If no files are given (`files=None`), all files will be staged."""
 63        if not files:
 64            return self.execute("add .")
 65        else:
 66            files = " ".join(f'"{file}"' for file in files)  # type: ignore
 67            return self.execute(f"add {files}")
 68
 69    def commit_files(self, files: list[str], message: str) -> str | int:
 70        """Stage and commit a list of files with commit message `message`."""
 71        return self.add(files) + self.commit(f'-m "{message}"')  # type: ignore
 72
 73    def initcommit(self) -> str | int:
 74        """Equivalent to
 75        >>> git add .
 76        >>> git commit -m "Initial commit" """
 77        return self.add() + self.commit('-m "Initial commit"')  # type: ignore
 78
 79    def amend(self, files: list[str] | None = None) -> str | int:
 80        """Stage and commit changes to the previous commit.
 81
 82        If `files` is `None`, all files will be staged.
 83
 84        Equivalent to:
 85        >>> git add {files}
 86        >>> git commit --amend --no-edit
 87        """
 88        return self.add(files) + self.commit("--amend --no-edit")  # type: ignore
 89
 90    def tag(self, args: str = "") -> str | int:
 91        """Execute the `tag` command with `args`.
 92
 93        e.g.
 94
 95        `self.tag("--sort=-committerdate")`
 96
 97        will list all the tags for this repository in descending commit date."""
 98        return self.execute(f"tag {args}")
 99
100    # ==========================================Push/Pull==========================================
101    def add_remote_url(self, url: str, name: str = "origin") -> str | int:
102        """Add remote url to repo."""
103        return self.execute(f"remote add {name} {url}")
104
105    def push(self, args: str = "") -> str | int:
106        """Equivalent to `git push {args}`."""
107        return self.execute(f"push {args}")
108
109    def pull(self, args: str = "") -> str | int:
110        """Equivalent to `git pull {args}`."""
111        return self.execute(f"pull {args}")
112
113    def push_new_branch(self, branch: str) -> str | int:
114        """Push a new branch to origin with tracking.
115
116        Equivalent to `git push -u origin {branch}`."""
117        return self.push(f"-u origin {branch}")
118
119    def pull_branch(self, branch: str) -> str | int:
120        """Pull `branch` from origin."""
121        return self.pull(f"origin {branch}")
122
123    # ============================================Checkout/Branches============================================
124    def branch(self, args: str = "") -> str | int:
125        """Equivalent to `git branch {args}`."""
126        return self.execute(f"branch {args}")
127
128    @property
129    def current_branch(self) -> str:
130        """Returns the name of the currently active branch."""
131        capturing_output = self.capture_stdout
132        current_branch = ""
133        with self.capture_output():
134            branches = self.branch().splitlines()  # type: ignore
135            for branch in branches:
136                if branch.startswith("*"):
137                    current_branch = branch[2:]
138                    break
139        self.capture_stdout = capturing_output
140        return current_branch
141
142    def list_branches(self) -> str | int:
143        """Print a list of branches."""
144        return self.branch("-vva")
145
146    def checkout(self, args: str) -> str | int:
147        """Equivalent to `git checkout {args}`."""
148        return self.execute(f"checkout {args}")
149
150    def switch_branch(self, branch_name: str) -> str | int:
151        """Switch to the branch specified by `branch_name`.
152
153        Equivalent to `git checkout {branch_name}`."""
154        return self.checkout(branch_name)
155
156    def create_new_branch(self, branch_name: str) -> str | int:
157        """Create and switch to a new branch named with `branch_name`.
158
159        Equivalent to `git checkout -b {branch_name} --track`."""
160        return self.checkout(f"-b {branch_name} --track")
161
162    def delete_branch(self, branch_name: str, local_only: bool = True) -> str | int:
163        """Delete `branch_name` from repo.
164
165        #### :params:
166
167        `local_only`: Only delete the local copy of `branch`, otherwise also delete the remote branch on origin and remote-tracking branch."""
168        output = self.branch(f"--delete {branch_name}")
169        if not local_only:
170            return output + self.push(f"origin --delete {branch_name}")  # type:ignore
171        return output
172
173    def undo(self) -> str | int:
174        """Undo uncommitted changes.
175
176        Equivalent to `git checkout .`."""
177        return self.checkout(".")
178
179    def merge(self, branch_name: str) -> str | int:
180        """Merge branch `branch_name` with currently active branch."""
181        return self.execute(f"merge {branch_name}")
182
183    # ===============================Requires GitHub CLI to be installed and configured===============================
184
185    def create_remote(self, name: str, public: bool = False) -> str | int:
186        """Uses GitHub CLI (must be installed and configured) to create a remote GitHub repo.
187
188        #### :params:
189
190        `name`: The name for the repo.
191
192        `public`: Set to `True` to create the repo as public, otherwise it'll be created as private."""
193        visibility = "--public" if public else "--private"
194        return self._run(["gh", "repo", "create", name, visibility])
195
196    def create_remote_from_cwd(self, public: bool = False) -> str | int:
197        """Use GitHub CLI (must be installed and configured) to create a remote GitHub repo from
198        the current working directory repo and add its url as this repo's remote origin.
199
200        #### :params:
201
202        `public`: Create the GitHub repo as a public repo, default is to create it as private."""
203        visibility = "public" if public else "private"
204        return self._run(
205            ["gh", "repo", "create", "--source", ".", f"--{visibility}", "--push"]
206        )
207
208    def _change_visibility(self, owner: str, name: str, visibility: str) -> str | int:
209        return self._run(
210            ["gh", "repo", "edit", f"{owner}/{name}", "--visibility", visibility]
211        )
212
213    def make_private(self, owner: str, name: str) -> str | int:
214        """Uses GitHub CLI (must be installed and configured) to set the repo's visibility to private.
215
216        #### :params:
217
218        `owner`: The repo owner.
219
220        `name`: The name of the repo to edit."""
221        return self._change_visibility(owner, name, "private")
222
223    def make_public(self, owner: str, name: str) -> str | int:
224        """Uses GitHub CLI (must be installed and configured) to set the repo's visibility to public.
225
226        #### :params:
227
228        `owner`: The repo owner.
229
230        `name`: The name of the repo to edit."""
231        return self._change_visibility(owner, name, "public")
232
233    def delete_remote(self, owner: str, name: str) -> str | int:
234        """Uses GitHub CLI (must be isntalled and configured) to delete the remote for this repo.
235
236        #### :params:
237
238        `owner`: The repo owner.
239
240        `name`: The name of the remote repo to delete."""
241        return self._run(["gh", "repo", "delete", f"{owner}/{name}", "--yes"])
class Git:
  8class Git:
  9    def __init__(self, capture_stdout: bool = False):
 10        """If `capture_stdout` is `True`, all functions will return their generated `stdout` as a string.
 11        Otherwise, the functions return the call's exit code."""
 12        self.capture_stdout = capture_stdout
 13
 14    @contextmanager
 15    def capture_output(self):
 16        self.capture_stdout = True
 17        yield self
 18        self.capture_stdout = False
 19
 20    @property
 21    def capture_stdout(self) -> bool:
 22        """If `True`, member functions will return the generated `stdout` as a string,
 23        otherwise they return the command's exit code."""
 24        return self._capture_stdout
 25
 26    @capture_stdout.setter
 27    def capture_stdout(self, should_capture: bool):
 28        self._capture_stdout = should_capture
 29
 30    def _run(self, args: list[str]) -> str | int:
 31        if self._capture_stdout:
 32            return subprocess.run(args, stdout=subprocess.PIPE, text=True).stdout
 33        else:
 34            return subprocess.run(args).returncode
 35
 36    def execute(self, command: str) -> str | int:
 37        """Execute git command.
 38
 39        Equivalent to executing `git {command}` in the shell."""
 40        args = ["git"] + shlex.split(command)
 41        return self._run(args)
 42
 43    def new_repo(self) -> str | int:
 44        """Executes `git init -b main`."""
 45        return self.execute("init -b main")
 46
 47    def loggy(self) -> str | int:
 48        """Equivalent to `git log --oneline --name-only --abbrev-commit --graph`."""
 49        return self.execute("log --oneline --name-only --abbrev-commit --graph")
 50
 51    def status(self) -> str | int:
 52        """Execute `git status`."""
 53        return self.execute("status")
 54
 55    # ======================================Staging/Committing======================================
 56    def commit(self, args: str) -> str | int:
 57        """>>> git commit {args}"""
 58        return self.execute(f"commit {args}")
 59
 60    def add(self, files: list[str] | None = None) -> str | int:
 61        """Stage a list of files.
 62
 63        If no files are given (`files=None`), all files will be staged."""
 64        if not files:
 65            return self.execute("add .")
 66        else:
 67            files = " ".join(f'"{file}"' for file in files)  # type: ignore
 68            return self.execute(f"add {files}")
 69
 70    def commit_files(self, files: list[str], message: str) -> str | int:
 71        """Stage and commit a list of files with commit message `message`."""
 72        return self.add(files) + self.commit(f'-m "{message}"')  # type: ignore
 73
 74    def initcommit(self) -> str | int:
 75        """Equivalent to
 76        >>> git add .
 77        >>> git commit -m "Initial commit" """
 78        return self.add() + self.commit('-m "Initial commit"')  # type: ignore
 79
 80    def amend(self, files: list[str] | None = None) -> str | int:
 81        """Stage and commit changes to the previous commit.
 82
 83        If `files` is `None`, all files will be staged.
 84
 85        Equivalent to:
 86        >>> git add {files}
 87        >>> git commit --amend --no-edit
 88        """
 89        return self.add(files) + self.commit("--amend --no-edit")  # type: ignore
 90
 91    def tag(self, args: str = "") -> str | int:
 92        """Execute the `tag` command with `args`.
 93
 94        e.g.
 95
 96        `self.tag("--sort=-committerdate")`
 97
 98        will list all the tags for this repository in descending commit date."""
 99        return self.execute(f"tag {args}")
100
101    # ==========================================Push/Pull==========================================
102    def add_remote_url(self, url: str, name: str = "origin") -> str | int:
103        """Add remote url to repo."""
104        return self.execute(f"remote add {name} {url}")
105
106    def push(self, args: str = "") -> str | int:
107        """Equivalent to `git push {args}`."""
108        return self.execute(f"push {args}")
109
110    def pull(self, args: str = "") -> str | int:
111        """Equivalent to `git pull {args}`."""
112        return self.execute(f"pull {args}")
113
114    def push_new_branch(self, branch: str) -> str | int:
115        """Push a new branch to origin with tracking.
116
117        Equivalent to `git push -u origin {branch}`."""
118        return self.push(f"-u origin {branch}")
119
120    def pull_branch(self, branch: str) -> str | int:
121        """Pull `branch` from origin."""
122        return self.pull(f"origin {branch}")
123
124    # ============================================Checkout/Branches============================================
125    def branch(self, args: str = "") -> str | int:
126        """Equivalent to `git branch {args}`."""
127        return self.execute(f"branch {args}")
128
129    @property
130    def current_branch(self) -> str:
131        """Returns the name of the currently active branch."""
132        capturing_output = self.capture_stdout
133        current_branch = ""
134        with self.capture_output():
135            branches = self.branch().splitlines()  # type: ignore
136            for branch in branches:
137                if branch.startswith("*"):
138                    current_branch = branch[2:]
139                    break
140        self.capture_stdout = capturing_output
141        return current_branch
142
143    def list_branches(self) -> str | int:
144        """Print a list of branches."""
145        return self.branch("-vva")
146
147    def checkout(self, args: str) -> str | int:
148        """Equivalent to `git checkout {args}`."""
149        return self.execute(f"checkout {args}")
150
151    def switch_branch(self, branch_name: str) -> str | int:
152        """Switch to the branch specified by `branch_name`.
153
154        Equivalent to `git checkout {branch_name}`."""
155        return self.checkout(branch_name)
156
157    def create_new_branch(self, branch_name: str) -> str | int:
158        """Create and switch to a new branch named with `branch_name`.
159
160        Equivalent to `git checkout -b {branch_name} --track`."""
161        return self.checkout(f"-b {branch_name} --track")
162
163    def delete_branch(self, branch_name: str, local_only: bool = True) -> str | int:
164        """Delete `branch_name` from repo.
165
166        #### :params:
167
168        `local_only`: Only delete the local copy of `branch`, otherwise also delete the remote branch on origin and remote-tracking branch."""
169        output = self.branch(f"--delete {branch_name}")
170        if not local_only:
171            return output + self.push(f"origin --delete {branch_name}")  # type:ignore
172        return output
173
174    def undo(self) -> str | int:
175        """Undo uncommitted changes.
176
177        Equivalent to `git checkout .`."""
178        return self.checkout(".")
179
180    def merge(self, branch_name: str) -> str | int:
181        """Merge branch `branch_name` with currently active branch."""
182        return self.execute(f"merge {branch_name}")
183
184    # ===============================Requires GitHub CLI to be installed and configured===============================
185
186    def create_remote(self, name: str, public: bool = False) -> str | int:
187        """Uses GitHub CLI (must be installed and configured) to create a remote GitHub repo.
188
189        #### :params:
190
191        `name`: The name for the repo.
192
193        `public`: Set to `True` to create the repo as public, otherwise it'll be created as private."""
194        visibility = "--public" if public else "--private"
195        return self._run(["gh", "repo", "create", name, visibility])
196
197    def create_remote_from_cwd(self, public: bool = False) -> str | int:
198        """Use GitHub CLI (must be installed and configured) to create a remote GitHub repo from
199        the current working directory repo and add its url as this repo's remote origin.
200
201        #### :params:
202
203        `public`: Create the GitHub repo as a public repo, default is to create it as private."""
204        visibility = "public" if public else "private"
205        return self._run(
206            ["gh", "repo", "create", "--source", ".", f"--{visibility}", "--push"]
207        )
208
209    def _change_visibility(self, owner: str, name: str, visibility: str) -> str | int:
210        return self._run(
211            ["gh", "repo", "edit", f"{owner}/{name}", "--visibility", visibility]
212        )
213
214    def make_private(self, owner: str, name: str) -> str | int:
215        """Uses GitHub CLI (must be installed and configured) to set the repo's visibility to private.
216
217        #### :params:
218
219        `owner`: The repo owner.
220
221        `name`: The name of the repo to edit."""
222        return self._change_visibility(owner, name, "private")
223
224    def make_public(self, owner: str, name: str) -> str | int:
225        """Uses GitHub CLI (must be installed and configured) to set the repo's visibility to public.
226
227        #### :params:
228
229        `owner`: The repo owner.
230
231        `name`: The name of the repo to edit."""
232        return self._change_visibility(owner, name, "public")
233
234    def delete_remote(self, owner: str, name: str) -> str | int:
235        """Uses GitHub CLI (must be isntalled and configured) to delete the remote for this repo.
236
237        #### :params:
238
239        `owner`: The repo owner.
240
241        `name`: The name of the remote repo to delete."""
242        return self._run(["gh", "repo", "delete", f"{owner}/{name}", "--yes"])
Git(capture_stdout: bool = False)
 9    def __init__(self, capture_stdout: bool = False):
10        """If `capture_stdout` is `True`, all functions will return their generated `stdout` as a string.
11        Otherwise, the functions return the call's exit code."""
12        self.capture_stdout = capture_stdout

If capture_stdout is True, all functions will return their generated stdout as a string. Otherwise, the functions return the call's exit code.

capture_stdout: bool

If True, member functions will return the generated stdout as a string, otherwise they return the command's exit code.

@contextmanager
def capture_output(self):
14    @contextmanager
15    def capture_output(self):
16        self.capture_stdout = True
17        yield self
18        self.capture_stdout = False
def execute(self, command: str) -> str | int:
36    def execute(self, command: str) -> str | int:
37        """Execute git command.
38
39        Equivalent to executing `git {command}` in the shell."""
40        args = ["git"] + shlex.split(command)
41        return self._run(args)

Execute git command.

Equivalent to executing git {command} in the shell.

def new_repo(self) -> str | int:
43    def new_repo(self) -> str | int:
44        """Executes `git init -b main`."""
45        return self.execute("init -b main")

Executes git init -b main.

def loggy(self) -> str | int:
47    def loggy(self) -> str | int:
48        """Equivalent to `git log --oneline --name-only --abbrev-commit --graph`."""
49        return self.execute("log --oneline --name-only --abbrev-commit --graph")

Equivalent to git log --oneline --name-only --abbrev-commit --graph.

def status(self) -> str | int:
51    def status(self) -> str | int:
52        """Execute `git status`."""
53        return self.execute("status")

Execute git status.

def commit(self, args: str) -> str | int:
56    def commit(self, args: str) -> str | int:
57        """>>> git commit {args}"""
58        return self.execute(f"commit {args}")
>>> git commit {args}
def add(self, files: list[str] | None = None) -> str | int:
60    def add(self, files: list[str] | None = None) -> str | int:
61        """Stage a list of files.
62
63        If no files are given (`files=None`), all files will be staged."""
64        if not files:
65            return self.execute("add .")
66        else:
67            files = " ".join(f'"{file}"' for file in files)  # type: ignore
68            return self.execute(f"add {files}")

Stage a list of files.

If no files are given (files=None), all files will be staged.

def commit_files(self, files: list[str], message: str) -> str | int:
70    def commit_files(self, files: list[str], message: str) -> str | int:
71        """Stage and commit a list of files with commit message `message`."""
72        return self.add(files) + self.commit(f'-m "{message}"')  # type: ignore

Stage and commit a list of files with commit message message.

def initcommit(self) -> str | int:
74    def initcommit(self) -> str | int:
75        """Equivalent to
76        >>> git add .
77        >>> git commit -m "Initial commit" """
78        return self.add() + self.commit('-m "Initial commit"')  # type: ignore

Equivalent to

>>> git add .
>>> git commit -m "Initial commit"
def amend(self, files: list[str] | None = None) -> str | int:
80    def amend(self, files: list[str] | None = None) -> str | int:
81        """Stage and commit changes to the previous commit.
82
83        If `files` is `None`, all files will be staged.
84
85        Equivalent to:
86        >>> git add {files}
87        >>> git commit --amend --no-edit
88        """
89        return self.add(files) + self.commit("--amend --no-edit")  # type: ignore

Stage and commit changes to the previous commit.

If files is None, all files will be staged.

Equivalent to:

>>> git add {files}
>>> git commit --amend --no-edit
def tag(self, args: str = '') -> str | int:
91    def tag(self, args: str = "") -> str | int:
92        """Execute the `tag` command with `args`.
93
94        e.g.
95
96        `self.tag("--sort=-committerdate")`
97
98        will list all the tags for this repository in descending commit date."""
99        return self.execute(f"tag {args}")

Execute the tag command with args.

e.g.

self.tag("--sort=-committerdate")

will list all the tags for this repository in descending commit date.

def add_remote_url(self, url: str, name: str = 'origin') -> str | int:
102    def add_remote_url(self, url: str, name: str = "origin") -> str | int:
103        """Add remote url to repo."""
104        return self.execute(f"remote add {name} {url}")

Add remote url to repo.

def push(self, args: str = '') -> str | int:
106    def push(self, args: str = "") -> str | int:
107        """Equivalent to `git push {args}`."""
108        return self.execute(f"push {args}")

Equivalent to git push {args}.

def pull(self, args: str = '') -> str | int:
110    def pull(self, args: str = "") -> str | int:
111        """Equivalent to `git pull {args}`."""
112        return self.execute(f"pull {args}")

Equivalent to git pull {args}.

def push_new_branch(self, branch: str) -> str | int:
114    def push_new_branch(self, branch: str) -> str | int:
115        """Push a new branch to origin with tracking.
116
117        Equivalent to `git push -u origin {branch}`."""
118        return self.push(f"-u origin {branch}")

Push a new branch to origin with tracking.

Equivalent to git push -u origin {branch}.

def pull_branch(self, branch: str) -> str | int:
120    def pull_branch(self, branch: str) -> str | int:
121        """Pull `branch` from origin."""
122        return self.pull(f"origin {branch}")

Pull branch from origin.

def branch(self, args: str = '') -> str | int:
125    def branch(self, args: str = "") -> str | int:
126        """Equivalent to `git branch {args}`."""
127        return self.execute(f"branch {args}")

Equivalent to git branch {args}.

current_branch: str

Returns the name of the currently active branch.

def list_branches(self) -> str | int:
143    def list_branches(self) -> str | int:
144        """Print a list of branches."""
145        return self.branch("-vva")

Print a list of branches.

def checkout(self, args: str) -> str | int:
147    def checkout(self, args: str) -> str | int:
148        """Equivalent to `git checkout {args}`."""
149        return self.execute(f"checkout {args}")

Equivalent to git checkout {args}.

def switch_branch(self, branch_name: str) -> str | int:
151    def switch_branch(self, branch_name: str) -> str | int:
152        """Switch to the branch specified by `branch_name`.
153
154        Equivalent to `git checkout {branch_name}`."""
155        return self.checkout(branch_name)

Switch to the branch specified by branch_name.

Equivalent to git checkout {branch_name}.

def create_new_branch(self, branch_name: str) -> str | int:
157    def create_new_branch(self, branch_name: str) -> str | int:
158        """Create and switch to a new branch named with `branch_name`.
159
160        Equivalent to `git checkout -b {branch_name} --track`."""
161        return self.checkout(f"-b {branch_name} --track")

Create and switch to a new branch named with branch_name.

Equivalent to git checkout -b {branch_name} --track.

def delete_branch(self, branch_name: str, local_only: bool = True) -> str | int:
163    def delete_branch(self, branch_name: str, local_only: bool = True) -> str | int:
164        """Delete `branch_name` from repo.
165
166        #### :params:
167
168        `local_only`: Only delete the local copy of `branch`, otherwise also delete the remote branch on origin and remote-tracking branch."""
169        output = self.branch(f"--delete {branch_name}")
170        if not local_only:
171            return output + self.push(f"origin --delete {branch_name}")  # type:ignore
172        return output

Delete branch_name from repo.

:params:

local_only: Only delete the local copy of branch, otherwise also delete the remote branch on origin and remote-tracking branch.

def undo(self) -> str | int:
174    def undo(self) -> str | int:
175        """Undo uncommitted changes.
176
177        Equivalent to `git checkout .`."""
178        return self.checkout(".")

Undo uncommitted changes.

Equivalent to git checkout ..

def merge(self, branch_name: str) -> str | int:
180    def merge(self, branch_name: str) -> str | int:
181        """Merge branch `branch_name` with currently active branch."""
182        return self.execute(f"merge {branch_name}")

Merge branch branch_name with currently active branch.

def create_remote(self, name: str, public: bool = False) -> str | int:
186    def create_remote(self, name: str, public: bool = False) -> str | int:
187        """Uses GitHub CLI (must be installed and configured) to create a remote GitHub repo.
188
189        #### :params:
190
191        `name`: The name for the repo.
192
193        `public`: Set to `True` to create the repo as public, otherwise it'll be created as private."""
194        visibility = "--public" if public else "--private"
195        return self._run(["gh", "repo", "create", name, visibility])

Uses GitHub CLI (must be installed and configured) to create a remote GitHub repo.

:params:

name: The name for the repo.

public: Set to True to create the repo as public, otherwise it'll be created as private.

def create_remote_from_cwd(self, public: bool = False) -> str | int:
197    def create_remote_from_cwd(self, public: bool = False) -> str | int:
198        """Use GitHub CLI (must be installed and configured) to create a remote GitHub repo from
199        the current working directory repo and add its url as this repo's remote origin.
200
201        #### :params:
202
203        `public`: Create the GitHub repo as a public repo, default is to create it as private."""
204        visibility = "public" if public else "private"
205        return self._run(
206            ["gh", "repo", "create", "--source", ".", f"--{visibility}", "--push"]
207        )

Use GitHub CLI (must be installed and configured) to create a remote GitHub repo from the current working directory repo and add its url as this repo's remote origin.

:params:

public: Create the GitHub repo as a public repo, default is to create it as private.

def make_private(self, owner: str, name: str) -> str | int:
214    def make_private(self, owner: str, name: str) -> str | int:
215        """Uses GitHub CLI (must be installed and configured) to set the repo's visibility to private.
216
217        #### :params:
218
219        `owner`: The repo owner.
220
221        `name`: The name of the repo to edit."""
222        return self._change_visibility(owner, name, "private")

Uses GitHub CLI (must be installed and configured) to set the repo's visibility to private.

:params:

owner: The repo owner.

name: The name of the repo to edit.

def make_public(self, owner: str, name: str) -> str | int:
224    def make_public(self, owner: str, name: str) -> str | int:
225        """Uses GitHub CLI (must be installed and configured) to set the repo's visibility to public.
226
227        #### :params:
228
229        `owner`: The repo owner.
230
231        `name`: The name of the repo to edit."""
232        return self._change_visibility(owner, name, "public")

Uses GitHub CLI (must be installed and configured) to set the repo's visibility to public.

:params:

owner: The repo owner.

name: The name of the repo to edit.

def delete_remote(self, owner: str, name: str) -> str | int:
234    def delete_remote(self, owner: str, name: str) -> str | int:
235        """Uses GitHub CLI (must be isntalled and configured) to delete the remote for this repo.
236
237        #### :params:
238
239        `owner`: The repo owner.
240
241        `name`: The name of the remote repo to delete."""
242        return self._run(["gh", "repo", "delete", f"{owner}/{name}", "--yes"])

Uses GitHub CLI (must be isntalled and configured) to delete the remote for this repo.

:params:

owner: The repo owner.

name: The name of the remote repo to delete.